-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_visual_features.py
35 lines (24 loc) · 1002 Bytes
/
test_visual_features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import torch
import pickle
from dataset import MELDDataset
from models.visual_features import detect_faces_mtcnn, get_face_embeddings
"""
File for testing the visual features module
"""
cascade_path = 'haarcascade_frontalface_default.xml'
audio_embed_path = "../MELD.Raw/audio_embeddings_feature_selection_sentiment.pkl"
train_audio_emb, val_audio_emb, test_audio_emb = pickle.load(open(audio_embed_path, 'rb'))
dataset = MELDDataset("../MELD.Raw/dev_sent_emo.csv", "../MELD.Raw/dev_splits_complete/", val_audio_emb)
video = dataset[3][0][1][0]
print(dataset[3][0])
face_tensors = detect_faces_mtcnn(video, display_images=False)
embeddings = get_face_embeddings(face_tensors)
def mse(vector):
zero_vec = vector[-1]
mse = []
for element in vector:
mse.append(torch.sum(torch.abs(element - vector)).item())
return mse
print(torch.sum(embeddings, axis=2))
print([mse(vector) for vector in embeddings])
# TODO: weirdly the facenet features don't return 0 for empty image.