• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cosanlab / py-feat / 15090929758

19 Oct 2024 05:10AM UTC coverage: 54.553%. First build
15090929758

push

github

web-flow
Merge pull request #228 from cosanlab/huggingface

WIP: Huggingface Integration

702 of 1620 new or added lines in 46 files covered. (43.33%)

3409 of 6249 relevant lines covered (54.55%)

3.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

22.22
/feat/emo_detectors/StatLearning/EmoSL_test.py
1
# Implements different statistical learning algorithms to classify Emotions
2
# Please see https://www.cl.cam.ac.uk/~mmam3/pub/FG2015.pdf for more details and reasons
3
# Currently support: SVM (as in the paper), RandomForest (new implementation).
4
import numpy as np
6✔
5

6

7
class EmoSVMClassifier:
6✔
8
    def __init__(self, **kwargs) -> None:
6✔
NEW
9
        self.weights_loaded = False
×
10

11
    def load_weights(self, scaler_full=None, pca_model_full=None, classifiers=None):
6✔
NEW
12
        self.scaler_full = scaler_full
×
NEW
13
        self.pca_model_full = pca_model_full
×
NEW
14
        self.classifiers = classifiers
×
NEW
15
        self.weights_loaded = True
×
16

17
    def pca_transform(self, frame, scaler, pca_model, landmarks):
6✔
NEW
18
        if not self.weights_loaded:
×
NEW
19
            raise ValueError("Need to load weights before running pca_transform")
×
20
        else:
NEW
21
            transformed_frame = pca_model.transform(scaler.transform(frame))
×
NEW
22
            return np.concatenate((transformed_frame, landmarks), axis=1)
×
23

24
    def detect_emo(self, frame, landmarks, **kwargs):
6✔
25
        """
26
        Note that here frame is represented by hogs
27
        """
NEW
28
        if not self.weights_loaded:
×
NEW
29
            raise ValueError("Need to load weights before running detect_au")
×
30
        else:
NEW
31
            landmarks = np.concatenate(landmarks)
×
NEW
32
            landmarks = landmarks.reshape(-1, landmarks.shape[1] * landmarks.shape[2])
×
33

NEW
34
            pca_transformed_full = self.pca_transform(
×
35
                frame, self.scaler_full, self.pca_model_full, landmarks
36
            )
NEW
37
            emo_columns = ["anger", "disgust", "fear", "happ", "sad", "sur", "neutral"]
×
38

NEW
39
            pred_emo = []
×
NEW
40
            for keys in emo_columns:
×
NEW
41
                emo_pred = self.classifiers[keys].predict(pca_transformed_full)
×
NEW
42
                pred_emo.append(emo_pred)
×
43

NEW
44
            pred_emos = np.array(pred_emo).T
×
NEW
45
            return pred_emos
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc