-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robin-WZQ
committed
Aug 12, 2021
0 parents
commit 27935b5
Showing
373 changed files
with
112,251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/venv | ||
/.idea |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- mode: python ; coding: utf-8 -*- | ||
|
||
block_cipher = None | ||
|
||
|
||
a = Analysis(['Emotion.py'], | ||
pathex=['/Users/zhuwenwen/Downloads/Emotion-Recongnition v1.2'], | ||
binaries=[], | ||
datas=[], | ||
hiddenimports=[], | ||
hookspath=[], | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
cipher=block_cipher, | ||
noarchive=False) | ||
pyz = PYZ(a.pure, a.zipped_data, | ||
cipher=block_cipher) | ||
exe = EXE(pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.zipfiles, | ||
a.datas, | ||
[], | ||
name='Emotion', | ||
debug=False, | ||
bootloader_ignore_signals=False, | ||
strip=False, | ||
upx=True, | ||
upx_exclude=[], | ||
runtime_tmpdir=None, | ||
console=True ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>1544</width> | ||
<height>849</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Emotion Recongnition v1.0</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<widget class="QLabel" name="label_camera"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>10</y> | ||
<width>1051</width> | ||
<height>631</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>视频播放区</string> | ||
</property> | ||
<property name="alignment"> | ||
<set>Qt::AlignCenter</set> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_face"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1100</x> | ||
<y>10</y> | ||
<width>401</width> | ||
<height>301</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>人脸检测区</string> | ||
</property> | ||
<property name="alignment"> | ||
<set>Qt::AlignCenter</set> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton_openfile"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>240</x> | ||
<y>740</y> | ||
<width>113</width> | ||
<height>51</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>选择文件</string> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton_play"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>400</x> | ||
<y>740</y> | ||
<width>113</width> | ||
<height>51</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>播放</string> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton_pause"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>560</x> | ||
<y>740</y> | ||
<width>113</width> | ||
<height>51</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>暂停</string> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_scanResult"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1210</x> | ||
<y>720</y> | ||
<width>281</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>识别结果</string> | ||
</property> | ||
<property name="alignment"> | ||
<set>Qt::AlignCenter</set> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1140</x> | ||
<y>720</y> | ||
<width>71</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>识别结果:</string> | ||
</property> | ||
</widget> | ||
<widget class="Line" name="line"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1070</x> | ||
<y>20</y> | ||
<width>20</width> | ||
<height>751</height> | ||
</rect> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
</widget> | ||
<widget class="Line" name="line_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1090</x> | ||
<y>330</y> | ||
<width>421</width> | ||
<height>16</height> | ||
</rect> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
</widget> | ||
<widget class="Line" name="line_3"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1100</x> | ||
<y>690</y> | ||
<width>411</width> | ||
<height>16</height> | ||
</rect> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
</widget> | ||
<widget class="QTextEdit" name="textEdit_model"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>1100</x> | ||
<y>360</y> | ||
<width>401</width> | ||
<height>311</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="pushButton_close"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>720</x> | ||
<y>740</y> | ||
<width>113</width> | ||
<height>51</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>关闭</string> | ||
</property> | ||
</widget> | ||
<widget class="QSlider" name="sld_video"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>170</x> | ||
<y>680</y> | ||
<width>731</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="maximum"> | ||
<number>100</number> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="lab_video"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>900</x> | ||
<y>650</y> | ||
<width>81</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>0%</string> | ||
</property> | ||
</widget> | ||
</widget> | ||
<widget class="QMenuBar" name="menubar"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>1544</width> | ||
<height>22</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from datasets.ve8 import VE8Dataset | ||
from torch.utils.data import DataLoader | ||
|
||
|
||
def get_ve8(image_path,audio_path,opt, subset, transforms): | ||
spatial_transform, temporal_transform, target_transform = transforms | ||
return VE8Dataset(image_path, | ||
audio_path, | ||
opt.annotation_path, | ||
subset, | ||
opt.fps, | ||
spatial_transform, | ||
temporal_transform, | ||
target_transform, | ||
need_audio=True) | ||
|
||
|
||
def get_training_set(opt, spatial_transform, temporal_transform, target_transform): | ||
if opt.dataset == 've8': | ||
transforms = [spatial_transform, temporal_transform, target_transform] | ||
return get_ve8(opt, 'training', transforms) | ||
else: | ||
raise Exception | ||
|
||
#新增了path在输入 | ||
def get_validation_set(image_path,audio_path,opt, spatial_transform, temporal_transform, target_transform): | ||
if opt.dataset == 've8': | ||
transforms = [spatial_transform, temporal_transform, target_transform] | ||
return get_ve8(image_path,audio_path , opt, 'validation', transforms) | ||
else: | ||
raise Exception | ||
|
||
|
||
def get_test_set(opt, spatial_transform, temporal_transform, target_transform): | ||
if opt.dataset == 've8': | ||
transforms = [spatial_transform, temporal_transform, target_transform] | ||
return get_ve8(opt, 'validation', transforms) | ||
else: | ||
raise Exception | ||
|
||
|
||
def get_data_loader(opt, dataset, shuffle, batch_size=0): | ||
batch_size = opt.batch_size if batch_size == 0 else batch_size | ||
return DataLoader( | ||
dataset, | ||
batch_size=batch_size, | ||
shuffle=shuffle, | ||
num_workers=opt.n_threads, | ||
pin_memory=True, | ||
drop_last=opt.dl | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import torch.nn as nn | ||
import torch.nn.functional as f | ||
from torch import Tensor | ||
import torch | ||
import numpy as np | ||
|
||
|
||
class PCCEVE8(nn.Module): | ||
""" | ||
0 Anger | ||
1 Anticipation | ||
2 Disgust | ||
3 Fear | ||
4 Joy | ||
5 Sadness | ||
6 Surprise | ||
7 Trust | ||
Positive: Anticipation, Joy, Surprise, Trust | ||
Negative: Anger, Disgust, Fear, Sadness | ||
""" | ||
|
||
def __init__(self, lambda_0=0): | ||
super(PCCEVE8, self).__init__() | ||
self.POSITIVE = {1, 4, 6, 7} | ||
self.NEGATIVE = {0, 2, 3, 5} | ||
|
||
self.lambda_0 = lambda_0 | ||
|
||
self.f0 = nn.CrossEntropyLoss(reduce=False) | ||
|
||
def forward(self, y_pred: Tensor, y: Tensor): | ||
batch_size = y_pred.size(0) | ||
weight = [1] * batch_size | ||
|
||
out = self.f0(y_pred, y) | ||
_, y_pred_label = f.softmax(y_pred, dim=1).topk(k=1, dim=1) | ||
y_pred_label = y_pred_label.squeeze(dim=1) | ||
y_numpy = y.cpu().numpy() | ||
y_pred_label_numpy = y_pred_label.cpu().numpy() | ||
for i, y_numpy_i, y_pred_label_numpy_i in zip(range(batch_size), y_numpy, y_pred_label_numpy): | ||
if (y_numpy_i in self.POSITIVE and y_pred_label_numpy_i in self.NEGATIVE) or ( | ||
y_numpy_i in self.NEGATIVE and y_pred_label_numpy_i in self.POSITIVE): | ||
weight[i] += self.lambda_0 | ||
weight_tensor = torch.from_numpy(np.array(weight)).cuda() | ||
out = out.mul(weight_tensor) | ||
out = torch.mean(out) | ||
|
||
return out | ||
|
||
|
||
def get_loss(opt): | ||
if opt.loss_func == 'ce': | ||
return nn.CrossEntropyLoss() | ||
elif opt.loss_func == 'pcce_ve8': | ||
return PCCEVE8(lambda_0=opt.lambda_0) | ||
else: | ||
raise Exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import torch.nn as nn | ||
from models.vaanet import VAANet | ||
|
||
|
||
def generate_model(opt): | ||
model = VAANet( | ||
snippet_duration=opt.snippet_duration, | ||
sample_size=opt.sample_size, | ||
n_classes=opt.n_classes, | ||
seq_len=opt.seq_len, | ||
audio_embed_size=opt.audio_embed_size, | ||
audio_n_segments=opt.audio_n_segments, | ||
pretrained_resnet101_path=opt.resnet101_pretrained, | ||
) | ||
model = model.cuda() | ||
|
||
return model, model.parameters() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import torch.nn as nn | ||
|
||
from torch.optim import Adam | ||
|
||
|
||
def get_optim(opt, parameters): | ||
optimizer = Adam(filter(lambda p: p.requires_grad, parameters), | ||
lr=opt.learning_rate, | ||
weight_decay=opt.weight_decay) | ||
return optimizer |
Oops, something went wrong.