psakamoori commited on
Commit
1db723d
1 Parent(s): 1cb0337

Run inference with OpenVINO backend

Browse files
Files changed (1) hide show
  1. README.md +152 -0
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: "en"
3
+ thumbnail:
4
+ tags:
5
+ - audio-classification
6
+ - speechbrain
7
+ - Emotion
8
+ - Recognition
9
+ - wav2vec2
10
+ - pytorch
11
+ license: "apache-2.0"
12
+ datasets:
13
+ - iemocap
14
+ metrics:
15
+ - Accuracy
16
+ inference: false
17
+ ---
18
+
19
+ <iframe src="https://ghbtns.com/github-btn.html?user=speechbrain&repo=speechbrain&type=star&count=true&size=large&v=2" frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
20
+ <br/><br/>
21
+
22
+ # Emotion Recognition with wav2vec2 base on IEMOCAP
23
+
24
+ This repository provides all the necessary tools to perform emotion recognition with a fine-tuned wav2vec2 (base) model using SpeechBrain.
25
+ It is trained on IEMOCAP training data.
26
+
27
+
28
+ For a better experience, we encourage you to learn more about
29
+ [SpeechBrain](https://speechbrain.github.io). The model performance on IEMOCAP test set is:
30
+
31
+ | Release | Accuracy(%) |
32
+ |:-------------:|:--------------:|
33
+ | 19-10-21 | 78.7 (Avg: 75.3) |
34
+
35
+
36
+ ## Pipeline description
37
+
38
+ This system is composed of an wav2vec2 model. It is a combination of convolutional and residual blocks. The embeddings are extracted using attentive statistical pooling. The system is trained with Additive Margin Softmax Loss. Speaker Verification is performed using cosine distance between speaker embeddings.
39
+
40
+ The system is trained with recordings sampled at 16kHz (single channel).
41
+ The code will automatically normalize your audio (i.e., resampling + mono channel selection) when calling *classify_file* if needed.
42
+
43
+
44
+ ## Install SpeechBrain
45
+
46
+ First of all, please install the **development** version of SpeechBrain with the following command:
47
+
48
+ ```
49
+ pip install git+https://github.com/speechbrain/speechbrain.git@$develop
50
+ ```
51
+
52
+ Please notice that we encourage you to read our tutorials and learn more about
53
+ [SpeechBrain](https://speechbrain.github.io).
54
+
55
+ ### Perform Emotion recognition
56
+
57
+ An external `py_module_file=custom.py` is used as an external Predictor class into this HF repos. We use `foreign_class` function from `speechbrain.pretrained.interfaces` that allow you to load you custom model.
58
+
59
+ ```python
60
+ from speechbrain.inference.interfaces import foreign_class
61
+ classifier = foreign_class(source="speechbrain/emotion-recognition-wav2vec2-IEMOCAP", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
62
+ out_prob, score, index, text_lab = classifier.classify_file("speechbrain/emotion-recognition-wav2vec2-IEMOCAP/anger.wav")
63
+ print(text_lab)
64
+ ```
65
+ The prediction tensor will contain a tuple of (embedding, id_class, label_name).
66
+
67
+ ### Perform Emotion recognition with OpenVINO backend
68
+
69
+ Unlocking the power of acceleration with [Intel OpenVINO](https://docs.openvino.ai/) runtime as inference "backend", deploy across a mix of [Intel® hardware and environments](https://docs.openvino.ai/2024/openvino-workflow/running-inference/inference-devices-and-modes.html), on-premises and on-device, in the browser or in the cloud. Passing backend as "openvino" in CustomEncoderWav2vec2Classifier class in custom_interface.py, which supports Intel OpenVINO backend to perform model inference with target device.
70
+
71
+ ### Steps to perform model inference with OpenVINO
72
+
73
+ #### Step 1: Install speechbrain and OpenVINO
74
+
75
+ First, ensure you have the necessary dependencies installed. Run the following commands to install the development version of SpeechBrain, OpenVINO, and the required version of the transformers library:
76
+
77
+ ```
78
+ pip install git+https://github.com/speechbrain/speechbrain.git@develop --extra-index-url https://download.pytorch.org/whl/cpu
79
+ pip install "openvino>=2024.1.0"
80
+ pip install "transformers>=4.30.0"
81
+ ```
82
+
83
+ #### Step 2: Run inference with OpenVINO backend
84
+
85
+ To run inference using the OpenVINO backend, you can use a sample application. Below is an example script (app.py) demonstrating how to set up and run the model inference:
86
+
87
+ ```
88
+ device = "cpu"
89
+ ov_opts = {"device_name": device, "PERFORMANCE_HINT": "LATENCY"}
90
+
91
+ instance = CustomEncoderWav2vec2Classifier(modules=checkpoint.mods,
92
+ hparams=hparams_dict, model=classifier.mods["wav2vec2"].model,
93
+ audio_file_path="speechbrain/emotion-recognition-wav2vec2-IEMOCAP/anger.wav",
94
+ backend="openvino",
95
+ ov_opts=ov_opts,
96
+ save_ov_model=False)
97
+ ```
98
+
99
+ To execute the application, simply run:
100
+ ```
101
+ python app.py
102
+ ```
103
+ For more detailed information on optimizing inference with OpenVINO, refer to the [OpenVINO Optimization Guide](
104
+ https://docs.openvino.ai/2024/openvino-workflow/running-inference/optimize-inference.html)
105
+
106
+ ### Inference on GPU
107
+ To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
108
+
109
+ ### Training
110
+ The model was trained with SpeechBrain (aa018540).
111
+ To train it from scratch follows these steps:
112
+ 1. Clone SpeechBrain:
113
+ ```bash
114
+ git clone https://github.com/speechbrain/speechbrain/
115
+ ```
116
+ 2. Install it:
117
+ ```
118
+ cd speechbrain
119
+ pip install -r requirements.txt
120
+ pip install -e .
121
+ ```
122
+
123
+ 3. Run Training:
124
+ ```
125
+ cd recipes/IEMOCAP/emotion_recognition
126
+ python train_with_wav2vec2.py hparams/train_with_wav2vec2.yaml --data_folder=your_data_folder
127
+ ```
128
+
129
+ You can find our training results (models, logs, etc) [here](https://drive.google.com/drive/folders/15dKQetLuAhSyg4sNOtbSDnuxFdEeU4zQ?usp=sharing).
130
+
131
+ ### Limitations
132
+ The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
133
+
134
+ # **Citing SpeechBrain**
135
+ Please, cite SpeechBrain if you use it for your research or business.
136
+
137
+ ```bibtex
138
+ @misc{speechbrain,
139
+ title={{SpeechBrain}: A General-Purpose Speech Toolkit},
140
+ author={Mirco Ravanelli and Titouan Parcollet and Peter Plantinga and Aku Rouhe and Samuele Cornell and Loren Lugosch and Cem Subakan and Nauman Dawalatabad and Abdelwahab Heba and Jianyuan Zhong and Ju-Chieh Chou and Sung-Lin Yeh and Szu-Wei Fu and Chien-Feng Liao and Elena Rastorgueva and François Grondin and William Aris and Hwidong Na and Yan Gao and Renato De Mori and Yoshua Bengio},
141
+ year={2021},
142
+ eprint={2106.04624},
143
+ archivePrefix={arXiv},
144
+ primaryClass={eess.AS},
145
+ note={arXiv:2106.04624}
146
+ }
147
+ ```
148
+
149
+ # **About SpeechBrain**
150
+ - Website: https://speechbrain.github.io/
151
+ - Code: https://github.com/speechbrain/speechbrain/
152
+ - HuggingFace: https://huggingface.co/speechbrain/