Skip to content

Commit e21f0c6

Browse files
authored
Merge pull request #86 from cosanlab/hog_aus
Hog aus
2 parents a793eb5 + a520145 commit e21f0c6

File tree

6 files changed

+1014
-115
lines changed

6 files changed

+1014
-115
lines changed

feat/au_detectors/DRML/DRML_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def forward(self, x):
9191

9292
if __name__ == "__main__":
9393
from torch.autograd import Variable
94-
9594
pic_x = Variable(torch.rand(8, 3, 170, 170))
9695
net = DRML_net(AU_num=12)
9796
print(net)

feat/au_detectors/DRML/DRML_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def detect_au(self, imgs, landmarks=None):
5858
pred_au = self.drml_net(input)
5959
all_pred_au = pred_au.data.cpu().float()
6060
# all_pred_au = (all_pred_au[:, 1, :]).exp()
61-
6261
# all_pred_au[all_pred_au < 0.5] = 0
6362
# all_pred_au[all_pred_au >= 0.5] = 1
6463
all_pred_au = all_pred_au.data.numpy()

feat/au_detectors/StatLearning/SL_test.py

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,96 +5,111 @@
55
import numpy as np
66
from sklearn.preprocessing import StandardScaler
77
from sklearn.decomposition import PCA
8-
from sklearn.metrics import classification_report,f1_score
8+
from sklearn.metrics import classification_report, f1_score
99
from sklearn.svm import LinearSVC, SVC
1010
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
1111
from sklearn.ensemble import RandomForestClassifier
1212
from sklearn.datasets import make_classification
1313
from sklearn.linear_model import LogisticRegression
1414
from feat.utils import get_resource_path
1515
import joblib
16-
import os
16+
import os
1717

1818

1919
def load_classifier(cf_path):
2020
clf = joblib.load(cf_path)
21-
return clf
21+
return clf
22+
2223

2324
class RandomForestClassifier():
2425
def __init__(self) -> None:
25-
self.pca_model = load_classifier(os.path.join(get_resource_path(),"hog_pca_all_emotio.joblib"))
26-
self.classifier = load_classifier(os.path.join(get_resource_path(), "RF_568.joblib"))
27-
self.scaler = load_classifier(os.path.join(get_resource_path(), "hog_scalar_aus.joblib"))
26+
self.pca_model = load_classifier(os.path.join(
27+
get_resource_path(), "hog_pca_all_emotio.joblib"))
28+
self.classifier = load_classifier(
29+
os.path.join(get_resource_path(), "RF_568.joblib"))
30+
self.scaler = load_classifier(os.path.join(
31+
get_resource_path(), "hog_scalar_aus.joblib"))
2832

2933
def detect_au(self, frame, landmarks):
3034
"""
3135
Note that here frame is represented by hogs
3236
"""
3337
if len(frame.shape) < 2:
34-
frame = frame.reshape(1,-1)
38+
frame = frame.reshape(1, -1)
3539
if len(landmarks.shape) > 1:
36-
landmarks = landmarks.flatten().reshape(1,-1)
37-
38-
pca_transformed_frame = self.pca_model.transform(self.scaler.fit_transform(frame))
39-
feature_cbd = np.concatenate((pca_transformed_frame,landmarks),1)
40+
landmarks = landmarks.flatten().reshape(1, -1)
41+
42+
pca_transformed_frame = self.pca_model.transform(
43+
self.scaler.fit_transform(frame))
44+
feature_cbd = np.concatenate((pca_transformed_frame, landmarks), 1)
4045
pred_aus = []
4146
for keys in self.classifier:
4247
au_pred = self.classifier[keys].predict_proba(feature_cbd)
43-
au_pred = au_pred[0,1]
48+
au_pred = au_pred[0, 1]
4449
pred_aus.append(au_pred)
4550

46-
pred_aus = np.array(pred_aus).reshape(1,-1)
51+
pred_aus = np.array(pred_aus).reshape(1, -1)
4752
return pred_aus
4853

4954

5055
class SVMClassifier():
5156
def __init__(self) -> None:
52-
self.pca_model = load_classifier(os.path.join(get_resource_path(),"hog_pca_all_emotio.joblib"))
53-
self.classifier = load_classifier(os.path.join(get_resource_path(),"svm_568.joblib"))
54-
self.scaler = load_classifier(os.path.join(get_resource_path(), "hog_scalar_aus.joblib"))
57+
self.pca_model = load_classifier(os.path.join(
58+
get_resource_path(), "hog_pca_all_emotio.joblib"))
59+
self.classifier = load_classifier(
60+
os.path.join(get_resource_path(), "svm_568.joblib"))
61+
self.scaler = load_classifier(os.path.join(
62+
get_resource_path(), "hog_scalar_aus.joblib"))
5563

5664
def detect_au(self, frame, landmarks):
5765
"""
5866
Note that here frame is represented by hogs
5967
"""
6068
if len(frame.shape) < 2:
61-
frame = frame.reshape(1,-1)
69+
frame = frame.reshape(1, -1)
6270
if len(landmarks.shape) > 1:
63-
landmarks = landmarks.flatten().reshape(1,-1)
64-
65-
pca_transformed_frame = self.pca_model.transform(self.scaler.fit_transform(frame))
66-
feature_cbd = np.concatenate((pca_transformed_frame,landmarks),1)
71+
landmarks = landmarks.flatten().reshape(1, -1)
72+
73+
pca_transformed_frame = self.pca_model.transform(
74+
self.scaler.fit_transform(frame))
75+
feature_cbd = np.concatenate((pca_transformed_frame, landmarks), 1)
6776
pred_aus = []
6877
for keys in self.classifier:
6978
au_pred = self.classifier[keys].predict(feature_cbd)
70-
au_pred = au_pred[0] # probably need to delete this
79+
au_pred = au_pred[0] # probably need to delete this
7180
pred_aus.append(au_pred)
7281

73-
pred_aus = np.array(pred_aus).reshape(1,-1)
82+
pred_aus = np.array(pred_aus).reshape(1, -1)
7483
return pred_aus
7584

85+
7686
class LogisticClassifier():
77-
87+
7888
def __init__(self) -> None:
79-
self.pca_model = load_classifier(os.path.join(get_resource_path(),"hog_pca_all_emotio.joblib"))
80-
self.classifier = load_classifier(os.path.join(get_resource_path(),"Logistic_520.joblib"))
81-
self.scaler = load_classifier(os.path.join(get_resource_path(), "hog_scalar_aus.joblib"))
89+
self.pca_model = load_classifier(os.path.join(
90+
get_resource_path(), "hog_pca_all_emotio.joblib"))
91+
self.classifier = load_classifier(os.path.join(
92+
get_resource_path(), "Logistic_520.joblib"))
93+
self.scaler = load_classifier(os.path.join(
94+
get_resource_path(), "hog_scalar_aus.joblib"))
95+
8296
def detect_au(self, frame, landmarks):
8397
"""
8498
Note that here frame is represented by hogs
8599
"""
86100
if len(frame.shape) < 2:
87-
frame = frame.reshape(1,-1)
101+
frame = frame.reshape(1, -1)
88102
if len(landmarks.shape) > 1:
89-
landmarks = landmarks.flatten().reshape(1,-1)
90-
91-
pca_transformed_frame = self.pca_model.transform(self.scaler.fit_transform(frame))
92-
feature_cbd = np.concatenate((pca_transformed_frame,landmarks),1)
103+
landmarks = landmarks.flatten().reshape(1, -1)
104+
105+
pca_transformed_frame = self.pca_model.transform(
106+
self.scaler.fit_transform(frame))
107+
feature_cbd = np.concatenate((pca_transformed_frame, landmarks), 1)
93108
pred_aus = []
94109
for keys in self.classifier:
95110
au_pred = self.classifier[keys].predict_proba(feature_cbd)
96-
au_pred = au_pred[0,1]
111+
au_pred = au_pred[0, 1]
97112
pred_aus.append(au_pred)
98113

99-
pred_aus = np.array(pred_aus).reshape(1,-1)
114+
pred_aus = np.array(pred_aus).reshape(1, -1)
100115
return pred_aus

0 commit comments

Comments
 (0)