Skip to content

Commit bf4d3a7

Browse files
committed
cog-ified
1 parent f272d7a commit bf4d3a7

17 files changed

+63
-29
lines changed

cog.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
build:
2+
python_version: "3.6"
3+
gpu: false
4+
python_packages:
5+
- pandas==1.1.5
6+
- numpy==1.17.3
7+
- wave==0.0.2
8+
- sklearn==0.0
9+
- librosa==0.6.3
10+
- soundfile==0.9.0
11+
- tqdm==4.28.1
12+
- matplotlib==2.2.3
13+
- pyaudio==0.2.11
14+
- numba==0.48
15+
system_packages:
16+
- "ffmpeg"
17+
- "portaudio19-dev"
18+
predict: "predict.py:EmoPredictor"

create_csv.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ def write_tess_ravdess_csv(emotions=["sad", "neutral", "happy"], train_name="tra
6969

7070
for category in emotions:
7171
# for training speech directory
72-
for i, path in enumerate(glob.glob(f"data/training/Actor_*/*_{category}.wav")):
72+
total_files = glob.glob(f"data/training/Actor_*/*_{category}.wav")
73+
for i, path in enumerate(total_files):
7374
train_target["path"].append(path)
7475
train_target["emotion"].append(category)
75-
if verbose:
76-
print(f"[TESS&RAVDESS] There are {i} training audio files for category:{category}")
76+
if verbose and total_files:
77+
print(f"[TESS&RAVDESS] There are {len(total_files)} training audio files for category:{category}")
7778

7879
# for validation speech directory
79-
for i, path in enumerate(glob.glob(f"data/validation/Actor_*/*_{category}.wav")):
80+
total_files = glob.glob(f"data/validation/Actor_*/*_{category}.wav")
81+
for i, path in enumerate(total_files):
8082
test_target["path"].append(path)
8183
test_target["emotion"].append(category)
82-
if verbose:
83-
print(f"[TESS&RAVDESS] There are {i} testing audio files for category:{category}")
84+
if verbose and total_files:
85+
print(f"[TESS&RAVDESS] There are {len(total_files)} testing audio files for category:{category}")
8486
pd.DataFrame(test_target).to_csv(test_name)
8587
pd.DataFrame(train_target).to_csv(train_name)
8688

deep_emotion_recognition.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,13 @@
33
import sys
44
stderr = sys.stderr
55
sys.stderr = open(os.devnull, 'w')
6-
import keras
7-
sys.stderr = stderr
8-
# to use CPU uncomment below code
9-
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # see issue #152
10-
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
11-
# disable tensorflow logs
12-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
136
import tensorflow as tf
147

15-
config = tf.ConfigProto(intra_op_parallelism_threads=5,
16-
inter_op_parallelism_threads=5,
17-
allow_soft_placement=True,
18-
device_count = {'CPU' : 1,
19-
'GPU' : 0}
20-
)
21-
from keras.layers import LSTM, GRU, Dense, Activation, LeakyReLU, Dropout
22-
from keras.layers import Conv1D, MaxPool1D, GlobalAveragePooling1D
23-
from keras.models import Sequential
24-
from keras.callbacks import ModelCheckpoint, TensorBoard
25-
from keras.utils import to_categorical
8+
from tensorflow.keras.layers import LSTM, GRU, Dense, Activation, LeakyReLU, Dropout
9+
from tensorflow.keras.layers import Conv1D, MaxPool1D, GlobalAveragePooling1D
10+
from tensorflow.keras.models import Sequential
11+
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
12+
from tensorflow.keras.utils import to_categorical
2613

2714
from sklearn.metrics import accuracy_score, mean_absolute_error, confusion_matrix
2815

@@ -264,7 +251,7 @@ def train(self, override=False):
264251
model_filename = self._get_model_filename()
265252

266253
self.checkpointer = ModelCheckpoint(model_filename, save_best_only=True, verbose=1)
267-
self.tensorboard = TensorBoard(log_dir=f"logs/{self.model_name}")
254+
self.tensorboard = TensorBoard(log_dir=os.path.join("logs", self.model_name))
268255

269256
self.history = self.model.fit(self.X_train, self.y_train,
270257
batch_size=self.batch_size,

emotion_recognition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def predict_proba(self, audio_path):
182182
feature = extract_feature(audio_path, **self.audio_config).reshape(1, -1)
183183
proba = self.model.predict_proba(feature)[0]
184184
result = {}
185-
for emotion, prob in zip(self.emotions, proba):
185+
for emotion, prob in zip(self.model.classes_, proba):
186186
result[emotion] = prob
187187
return result
188188
else:
1.02 MB
Binary file not shown.
-1.1 MB
Binary file not shown.
689 KB
Binary file not shown.
-771 KB
Binary file not shown.
5.35 MB
Binary file not shown.
-5.44 MB
Binary file not shown.

0 commit comments

Comments
 (0)