Skip to content

Commit 3098b83

Browse files
committed
update README to add one more example
1 parent a04e5dc commit 3098b83

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ print("Prediction:", rec.predict("data/tess_ravdess/validation/Actor_25/25_01_01
103103
Prediction: neutral
104104
Prediction: sad
105105
```
106+
You can pass any audio file, if it's not in the appropriate format (16000Hz and mono channel), then it'll be automatically converted, make sure you have `ffmpeg` installed in your system and added to *PATH*.
106107
## Example 2: Using RNNs for 5 Emotions
107108
```python
108109
from deep_emotion_recognition import DeepEmotionRecognizer
@@ -144,6 +145,45 @@ true_neutral 3.846154 8.974360 82.051285 2.564103
144145
true_ps 2.564103 0.000000 1.282051 83.333328 12.820514
145146
true_happy 20.512821 2.564103 2.564103 2.564103 71.794876
146147
```
148+
## Example 3: Not Passing any Model and Removing the Custom Dataset
149+
Below code initializes `EmotionRecognizer` with 3 chosen emotions while removing Custom dataset, and setting `balance` to `False`:
150+
```python
151+
from emotion_recognition import EmotionRecognizer
152+
# initialize instance, this will take a bit the first time executed
153+
# as it'll extract the features and calls determine_best_model() automatically
154+
# to load the best performing model on the picked dataset
155+
rec = EmotionRecognizer(emotions=["angry", "neutral", "sad"], balance=False, verbose=1, custom_db=False)
156+
# it will be trained, so no need to train this time
157+
# get the accuracy on the test set
158+
print(rec.confusion_matrix())
159+
# predict angry audio sample
160+
prediction = rec.predict('data/validation/Actor_10/03-02-05-02-02-02-10_angry.wav')
161+
print(f"Prediction: {prediction}")
162+
```
163+
**Output:**
164+
```
165+
[+] Best model determined: RandomForestClassifier with 93.454% test accuracy
166+
167+
predicted_angry predicted_neutral predicted_sad
168+
true_angry 98.275864 1.149425 0.574713
169+
true_neutral 0.917431 88.073395 11.009174
170+
true_sad 6.250000 1.875000 91.875000
171+
172+
Prediction: angry
173+
```
174+
You can print the number of samples on each class:
175+
```python
176+
rec.get_samples_by_class()
177+
```
178+
**Output:**
179+
```
180+
train test total
181+
angry 910 174 1084
182+
neutral 650 109 759
183+
sad 862 160 1022
184+
total 2422 443 2865
185+
```
186+
In this case, the dataset is only from TESS and RAVDESS, and not balanced, you can pass `True` to `balance` on the `EmotionRecognizer` instance to balance the data.
147187
## Algorithms Used
148188
This repository can be used to build machine learning classifiers as well as regressors for the case of 3 emotions {'sad': 0, 'neutral': 1, 'happy': 2} and the case of 5 emotions {'angry': 1, 'sad': 2, 'neutral': 3, 'ps': 4, 'happy': 5}
149189
### Classifiers

0 commit comments

Comments
 (0)