vkushwahaa commited on
Commit
3cd07d4
·
verified ·
1 Parent(s): d9a10b2

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,2 +1,7 @@
1
  assets/summary_plot.png filter=lfs diff=lfs merge=lfs -text
2
  model.weights.h5 filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
1
  assets/summary_plot.png filter=lfs diff=lfs merge=lfs -text
2
  model.weights.h5 filter=lfs diff=lfs merge=lfs -text
3
+ X_test.npy filter=lfs diff=lfs merge=lfs -text
4
+ X_train.npy filter=lfs diff=lfs merge=lfs -text
5
+ best_emotion_model.keras filter=lfs diff=lfs merge=lfs -text
6
+ emotion_recognition_model.keras filter=lfs diff=lfs merge=lfs -text
7
+ emotion_recognition_wrapper_model.keras filter=lfs diff=lfs merge=lfs -text
X_test.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecb935710198621df6f1bdb36dc4530670a1669ed9be3daebd865cb97ef326ab
3
+ size 134535296
X_train.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3038748e3715c1a2e0f46ef61fe7e5207860c4404d7009ccace38d25fdf108f7
3
+ size 537974912
best_emotion_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f7823e7ee344145eb360514117a4cc67e93c65b68547bc68a7f8c042404940b
3
+ size 82992300
emotion.csv ADDED
The diff for this file is too large to render. See raw diff
 
emotion_recognition_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58caaef2a85c3f86339dbbf5731110fdee9aaa05888b0b7319b4ea20dbc781e7
3
+ size 82992300
emotion_recognition_wrapper_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b419cbe69b28b7f2630b6df7e5e924cb5b422d0da3d0debd9e73f89b40c23b08
3
+ size 82983662
example_usage.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import json
5
+ import librosa
6
+ import os
7
+
8
+ def load_model(model_path):
9
+ "Load the emotion recognition model."
10
+ return tf.keras.models.load_model(model_path)
11
+
12
+ def predict_emotion(model, audio_path, preprocessing_config):
13
+ "Predict emotion from an audio file."
14
+ # Load audio file
15
+ waveform, sr = librosa.load(
16
+ audio_path,
17
+ sr=preprocessing_config["sample_rate"],
18
+ duration=preprocessing_config["duration"],
19
+ offset=preprocessing_config["offset"]
20
+ )
21
+
22
+ # Ensure consistent length
23
+ target_length = int(preprocessing_config["sample_rate"] * preprocessing_config["duration"])
24
+ if len(waveform) < target_length:
25
+ waveform = np.pad(waveform, (0, target_length - len(waveform)))
26
+ if len(waveform) > target_length:
27
+ waveform = waveform[:target_length]
28
+
29
+ # Extract features
30
+ mel_spec = librosa.feature.melspectrogram(
31
+ y=waveform,
32
+ sr=preprocessing_config["sample_rate"],
33
+ n_fft=preprocessing_config["frame_length"],
34
+ hop_length=preprocessing_config["hop_length"],
35
+ n_mels=128
36
+ )
37
+
38
+ # Convert to log scale
39
+ log_mel = np.log(np.maximum(mel_spec, 1e-10))
40
+
41
+ # Add batch and channel dimensions
42
+ features = np.expand_dims(np.expand_dims(log_mel, axis=0), axis=-1)
43
+
44
+ # Make prediction
45
+ prediction = model.predict(features)[0]
46
+
47
+ # Get emotion label
48
+ emotion_idx = np.argmax(prediction)
49
+ emotion = preprocessing_config["emotions"][str(emotion_idx)]
50
+
51
+ return emotion, prediction[emotion_idx]
52
+
53
+ # Example usage
54
+ if __name__ == "__main__":
55
+ # Load model
56
+ model = load_model("emotion_recognition_model.keras")
57
+
58
+ # Load preprocessing config
59
+ with open("preprocessing.json", "r") as f:
60
+ preprocessing_config = json.load(f)
61
+
62
+ # Path to your audio file
63
+ audio_path = "path/to/your/audio.wav"
64
+
65
+ # Predict emotion
66
+ emotion, confidence = predict_emotion(model, audio_path, preprocessing_config)
67
+
68
+ print(f"Predicted emotion: {emotion} with confidence {confidence:.2f}")
label_mapping.pkl ADDED
Binary file (90 Bytes). View file
 
preprocessing.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "sample_rate": 22050,
3
+ "duration": 2.5,
4
+ "offset": 0.6,
5
+ "frame_length": 2048,
6
+ "hop_length": 512,
7
+ "emotions": {
8
+ "0": "angry",
9
+ "1": "disgust",
10
+ "2": "fear",
11
+ "3": "happy",
12
+ "4": "neutral",
13
+ "5": "sad",
14
+ "6": "surprise"
15
+ }
16
+ }
train_mean.npy ADDED
Binary file (55.4 kB). View file
 
train_std.npy ADDED
Binary file (55.4 kB). View file
 
training_history.png ADDED
y_test.npy ADDED
Binary file (19.6 kB). View file
 
y_train.npy ADDED
Binary file (78 kB). View file