harshit345
commited on
Commit
•
2c372c0
1
Parent(s):
f7cac30
Update README.md
Browse files
README.md
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
---
|
2 |
language: en
|
3 |
-
datasets:
|
|
|
4 |
tags:
|
5 |
- audio
|
6 |
-
-
|
7 |
- speech
|
8 |
-
- speech-emotion-recognition
|
9 |
license: apache-2.0
|
10 |
---
|
11 |
-
|
12 |
-
## How to use
|
13 |
-
### Requirements
|
14 |
-
```bash
|
15 |
# requirement packages
|
16 |
!pip install git+https://github.com/huggingface/datasets.git
|
17 |
!pip install git+https://github.com/huggingface/transformers.git
|
18 |
!pip install torchaudio
|
19 |
!pip install librosa
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
import torch
|
24 |
import torch.nn as nn
|
25 |
import torch.nn.functional as F
|
@@ -29,16 +28,16 @@ import librosa
|
|
29 |
import IPython.display as ipd
|
30 |
import numpy as np
|
31 |
import pandas as pd
|
32 |
-
|
33 |
-
|
34 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
35 |
-
model_name_or_path = "
|
36 |
config = AutoConfig.from_pretrained(model_name_or_path)
|
37 |
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name_or_path)
|
38 |
sampling_rate = feature_extractor.sampling_rate
|
39 |
model = Wav2Vec2ForSpeechClassification.from_pretrained(model_name_or_path).to(device)
|
40 |
-
|
41 |
-
|
42 |
def speech_file_to_array_fn(path, sampling_rate):
|
43 |
speech_array, _sampling_rate = torchaudio.load(path)
|
44 |
resampler = torchaudio.transforms.Resample(_sampling_rate)
|
@@ -53,37 +52,17 @@ def predict(path, sampling_rate):
|
|
53 |
scores = F.softmax(logits, dim=1).detach().cpu().numpy()[0]
|
54 |
outputs = [{"Emotion": config.id2label[i], "Score": f"{round(score * 100, 3):.1f}%"} for i, score in enumerate(scores)]
|
55 |
return outputs
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
59 |
outputs = predict(path, sampling_rate)
|
60 |
-
|
61 |
-
|
62 |
-
[
|
63 |
-
{'Emotion': '
|
64 |
-
{'Emotion': '
|
65 |
-
{'Emotion': '
|
66 |
-
{'Emotion': '
|
67 |
-
|
68 |
-
]
|
69 |
-
```
|
70 |
-
|
71 |
-
|
72 |
-
## Evaluation
|
73 |
-
The following tables summarize the scores obtained by model overall and per each class.
|
74 |
-
|
75 |
-
|
76 |
-
| Emotions | precision | recall | f1-score | accuracy |
|
77 |
-
|-----------|-----------|--------|----------|----------|
|
78 |
-
| anger | 0.82 | 1.00 | 0.81 | |
|
79 |
-
| disgust | 0.85 | 0.96 | 0.85 | |
|
80 |
-
| fear | 0.78 | 0.88 | 0.80 | |
|
81 |
-
| happiness | 0.84 | 0.71 | 0.78 | |
|
82 |
-
| sadness | 0.86 | 1.00 | 0.79 | |
|
83 |
-
| | | | Overall | 0.806 |
|
84 |
-
|
85 |
-
|
86 |
-
##
|
87 |
-
|
88 |
-
Colab Notebook
|
89 |
-
https://colab.research.google.com/drive/1aPPb_ZVS5dlFVZySly8Q80a44La1XjJu?usp=sharing
|
|
|
1 |
---
|
2 |
language: en
|
3 |
+
datasets:
|
4 |
+
- aesdd
|
5 |
tags:
|
6 |
- audio
|
7 |
+
- audio-classification
|
8 |
- speech
|
|
|
9 |
license: apache-2.0
|
10 |
---
|
11 |
+
~~~
|
|
|
|
|
|
|
12 |
# requirement packages
|
13 |
!pip install git+https://github.com/huggingface/datasets.git
|
14 |
!pip install git+https://github.com/huggingface/transformers.git
|
15 |
!pip install torchaudio
|
16 |
!pip install librosa
|
17 |
+
!git clone https://github.com/m3hrdadfi/soxan
|
18 |
+
cd soxan
|
19 |
+
~~~
|
20 |
+
# prediction
|
21 |
+
~~~
|
22 |
import torch
|
23 |
import torch.nn as nn
|
24 |
import torch.nn.functional as F
|
|
|
28 |
import IPython.display as ipd
|
29 |
import numpy as np
|
30 |
import pandas as pd
|
31 |
+
~~~
|
32 |
+
~~~
|
33 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
34 |
+
model_name_or_path = "Bagus/wav2vec2-xlsr-greek-speech-emotion-recognition"
|
35 |
config = AutoConfig.from_pretrained(model_name_or_path)
|
36 |
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_name_or_path)
|
37 |
sampling_rate = feature_extractor.sampling_rate
|
38 |
model = Wav2Vec2ForSpeechClassification.from_pretrained(model_name_or_path).to(device)
|
39 |
+
~~~
|
40 |
+
~~~
|
41 |
def speech_file_to_array_fn(path, sampling_rate):
|
42 |
speech_array, _sampling_rate = torchaudio.load(path)
|
43 |
resampler = torchaudio.transforms.Resample(_sampling_rate)
|
|
|
52 |
scores = F.softmax(logits, dim=1).detach().cpu().numpy()[0]
|
53 |
outputs = [{"Emotion": config.id2label[i], "Score": f"{round(score * 100, 3):.1f}%"} for i, score in enumerate(scores)]
|
54 |
return outputs
|
55 |
+
~~~
|
56 |
+
# prediction
|
57 |
+
~~~
|
58 |
+
# path for a sample
|
59 |
+
path = '/data/jtes_v1.1/wav/f01/ang/f01_ang_01.wav'
|
60 |
outputs = predict(path, sampling_rate)
|
61 |
+
~~~
|
62 |
+
~~~
|
63 |
+
[{'Emotion': 'anger', 'Score': '98.3%'},
|
64 |
+
{'Emotion': 'disgust', 'Score': '0.0%'},
|
65 |
+
{'Emotion': 'fear', 'Score': '0.4%'},
|
66 |
+
{'Emotion': 'happiness', 'Score': '0.7%'},
|
67 |
+
{'Emotion': 'sadness', 'Score': '0.5%'}]
|
68 |
+
~~~
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|