Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate emotions recognition #51

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

WojciechBarczynski
Copy link
Member

@WojciechBarczynski WojciechBarczynski commented Nov 6, 2024

Closes #17

Changes

  • A new component - task.emotion.Estimator allows estimating emotional "score" of an actor based on the face detection
  • visualization.Visualizer annotates face bounding boxes with emotion labels

@integraledelebesgue integraledelebesgue changed the title Emotions integration Introduced emotions recognition Nov 6, 2024
child_lab_framework/task/emotions/emotions.py Outdated Show resolved Hide resolved
child_lab_framework/task/emotions/emotions.py Outdated Show resolved Hide resolved
face_emotions = []
boxes = []
frame_height, frame_width, _ = frame.shape
for face_box in faces.boxes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

faces.boxes reference is not safe since faces can be None. This function should return Result | None and perform a check on faces

Copy link
Member

@integraledelebesgue integraledelebesgue Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, predict method should take not-none arguments. You can rename this method to __predict_safe and use it in stream and predict_batch.

Comment on lines +19 to +20
emotions: list[float]
boxes: list[FloatArray2]
Copy link
Member

@integraledelebesgue integraledelebesgue Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could stack these results and store them as np.ndarrays instead of lists. We do so in other Results in general

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's no use duplicating face.Result as boxes here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is - that way there is no coupling between emotion recognition and face detection in the visualization layer.

Duplicating it is almost free (the cost of doing that is negligible), but it's much easier to handle it that way in the visualization layer.

Comment on lines +19 to +25
class Result:
emotions: list[float]
boxes: list[FloatArray2]

def __init__(self, emotions: list[float], boxes: list[FloatArray2]) -> None:
self.emotions = emotions
self.boxes = boxes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a frozen dataclass

child_lab_framework/task/emotion/emotion.py Outdated Show resolved Hide resolved
Comment on lines 93 to 101
scores = {
'angry': -0.05,
'disgust': 0,
'fear': -0.07,
'happy': 1,
'sad': -1,
'surprise': 0,
'neutral': 0,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dict shouldn't be located here since it is going to be created on each call 💀 Please make it a private constant

Copy link
Member

@integraledelebesgue integraledelebesgue Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this in mind - how about making this dict injected into an Estimator via constructor?

child_lab_framework/task/emotion/emotion.py Show resolved Hide resolved
child_lab_framework/task/emotion/emotion.py Outdated Show resolved Hide resolved
Comment on lines +19 to +20
emotions: list[float]
boxes: list[FloatArray2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's no use duplicating face.Result as boxes here

@WojciechBarczynski WojciechBarczynski changed the title Introduced emotions recognition Integrate emotions recognition Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Facial Recognition component
2 participants