Dafisnadhifs commited on
Commit
43c4902
·
1 Parent(s): 04fd981

Add emotion recognition models (CNN, TFLite, TFJS)

Browse files
README.md CHANGED
@@ -1,3 +1,115 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ tags:
4
+ - image-classification
5
+ - tensorflow
6
+ - keras
7
+ - emotion-recognition
8
+ - facial-expression
9
+ - cnn
10
+ - tflite
11
+ - tfjs
12
+ datasets:
13
+ - samithsachidanandan/human-face-emotions
14
+ metrics:
15
+ - accuracy
16
+ pipeline_tag: image-classification
17
+ library_name: keras
18
  ---
19
+
20
+ # Human Emotion Recognition
21
+
22
+ Deep learning models for classifying human facial emotions.
23
+
24
+ ## Emotion Classes
25
+ - 😠 Angry
26
+ - 😨 Fear
27
+ - 😊 Happy
28
+ - 😢 Sad
29
+ - 😲 Surprise
30
+
31
+ ## Model Performance
32
+
33
+ | Model | Test Accuracy | Test Loss | Epochs |
34
+ |-------|---------------|-----------|--------|
35
+ | **Base CNN** | **92.41%** | 0.268 | 33 |
36
+ | MobileNetV3Small | 81.56% | 0.551 | 50 |
37
+
38
+ > 🏆 Best model: **Base CNN** with 92.41% test accuracy
39
+
40
+ ## Models
41
+
42
+ | File | Format | Input Size | Description |
43
+ |------|--------|------------|-------------|
44
+ | `model_base.h5` | Keras H5 | 128x128x1 | Custom CNN (Grayscale) |
45
+ | `model_transfer_learning.keras` | Keras | 224x224x3 | MobileNetV3Small (RGB) |
46
+ | `tflite/best_model.tflite` | TFLite | 128x128x1 | Mobile/Edge |
47
+ | `tfjs_model/` | TF.js | 128x128x1 | Web deployment |
48
+
49
+ ## Usage
50
+
51
+ ### Python
52
+
53
+ ```python
54
+ from huggingface_hub import hf_hub_download
55
+ import tensorflow as tf
56
+ import numpy as np
57
+
58
+ # Download model
59
+ model_path = hf_hub_download(
60
+ repo_id="dafisnadhif/human-emotion-recognition",
61
+ filename="model_base.h5"
62
+ )
63
+
64
+ # Load model
65
+ model = tf.keras.models.load_model(model_path)
66
+
67
+ # Predict
68
+ CLASS_NAMES = ['Angry', 'Fear', 'Happy', 'Sad', 'Surprise']
69
+ predictions = model.predict(img_batch)
70
+ print(CLASS_NAMES[np.argmax(predictions[0])])
71
+ ```
72
+
73
+ ### TensorFlow Lite
74
+
75
+ ```python
76
+ from huggingface_hub import hf_hub_download
77
+ import tensorflow as tf
78
+
79
+ tflite_path = hf_hub_download(
80
+ repo_id="dafisnadhif/human-emotion-recognition",
81
+ filename="tflite/best_model.tflite"
82
+ )
83
+
84
+ interpreter = tf.lite.Interpreter(model_path=tflite_path)
85
+ interpreter.allocate_tensors()
86
+ ```
87
+
88
+ ### TensorFlow.js
89
+
90
+ ```javascript
91
+ const model = await tf.loadLayersModel(
92
+ 'https://huggingface.co/dafisnadhif/human-emotion-recognition/resolve/main/tfjs_model/model.json'
93
+ );
94
+ ```
95
+
96
+ ## Training Details
97
+
98
+ | Parameter | Value |
99
+ |-----------|-------|
100
+ | **Dataset** | [Human Face Emotions](https://www.kaggle.com/datasets/samithsachidanandan/human-face-emotions) |
101
+ | **Images** | ~47,000 facial images |
102
+ | **Source Code** | [GitHub](https://github.com/DafisNadhifSaputra/human-emotion-recognition) |
103
+ | **Framework** | TensorFlow 2.x / Keras |
104
+ | **Optimizer** | AdamW (lr=1e-3, weight_decay=1e-4) |
105
+ | **Loss** | Sparse Categorical Crossentropy |
106
+ | **Batch Size** | 256 |
107
+ | **Callbacks** | EarlyStopping (patience=8), ReduceLROnPlateau |
108
+
109
+ ## License
110
+
111
+ MIT License
112
+
113
+ ## Author
114
+
115
+ Dafis Nadhif Saputra
model_base.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:964e54bed5f53efddb1dbcfaebdc16f1909b4b9961aaee1c87003cd4f78a70ac
3
+ size 13376000
tfjs_model/group1-shard1of2.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3c58be73182d8a009b235d8ff6c8befc0a3748fc6bc988374fd446faafa4780
3
+ size 4194304
tfjs_model/group1-shard2of2.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7ea3f59763dc3c26d4eeda0f6bb9398bf1124b571b0b06da1ffa52b53132f79
3
+ size 235796
tfjs_model/model.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"format": "layers-model", "generatedBy": "keras v3.8.0", "convertedBy": "TensorFlow.js Converter v4.22.0", "modelTopology": {"keras_version": "3.8.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential_33", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "layers": [{"class_name": "InputLayer", "config": {"batch_shape": [null, 128, 128, 1], "dtype": "float32", "sparse": false, "name": "input_layer_56"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_28", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "HeNormal", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "BatchNormalization", "config": {"name": "batch_normalization_37", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "gamma_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "moving_mean_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "moving_variance_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null, "synchronized": false}}, {"class_name": "Activation", "config": {"name": "activation_313", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "activation": "relu"}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_28", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}}, {"class_name": "Dropout", "config": {"name": "dropout_47", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "rate": 0.1, "seed": null, "noise_shape": null}}, {"class_name": "Conv2D", "config": {"name": "conv2d_29", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "filters": 64, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "HeNormal", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "BatchNormalization", "config": {"name": "batch_normalization_38", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "gamma_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "moving_mean_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "moving_variance_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null, "synchronized": false}}, {"class_name": "Activation", "config": {"name": "activation_314", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "activation": "relu"}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_29", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_30", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "filters": 64, "kernel_size": [3, 3], "strides": [1, 1], "padding": "same", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "HeNormal", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "BatchNormalization", "config": {"name": "batch_normalization_39", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "gamma_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "moving_mean_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "moving_variance_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null, "synchronized": false}}, {"class_name": "Activation", "config": {"name": "activation_315", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "activation": "relu"}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_30", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "pool_size": [4, 4], "padding": "valid", "strides": [4, 4], "data_format": "channels_last"}}, {"class_name": "Dropout", "config": {"name": "dropout_48", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "rate": 0.25, "seed": null, "noise_shape": null}}, {"class_name": "Flatten", "config": {"name": "flatten_12", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "data_format": "channels_last"}}, {"class_name": "Dense", "config": {"name": "dense_62", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "units": 256, "activation": "linear", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "BatchNormalization", "config": {"name": "batch_normalization_40", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "axis": -1, "momentum": 0.99, "epsilon": 0.001, "center": true, "scale": true, "beta_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "gamma_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "moving_mean_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "moving_variance_initializer": {"module": "keras.initializers", "class_name": "Ones", "config": {}, "registered_name": null}, "beta_regularizer": null, "gamma_regularizer": null, "beta_constraint": null, "gamma_constraint": null, "synchronized": false}}, {"class_name": "Activation", "config": {"name": "activation_316", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "activation": "relu"}}, {"class_name": "Dropout", "config": {"name": "dropout_49", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "rate": 0.5, "seed": null, "noise_shape": null}}, {"class_name": "Dense", "config": {"name": "dense_63", "trainable": true, "dtype": {"module": "keras", "class_name": "DTypePolicy", "config": {"name": "float32"}, "registered_name": null}, "units": 5, "activation": "softmax", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}], "build_input_shape": [null, 128, 128, 1]}}, "training_config": {"loss": "sparse_categorical_crossentropy", "loss_weights": null, "metrics": ["accuracy"], "weighted_metrics": null, "run_eagerly": false, "steps_per_execution": 1, "jit_compile": true, "optimizer_config": {"class_name": "AdamW", "config": {"name": "adamw", "learning_rate": 1.0000001111620804e-06, "weight_decay": 0.0001, "clipnorm": null, "global_clipnorm": null, "clipvalue": null, "use_ema": false, "ema_momentum": 0.99, "ema_overwrite_frequency": null, "loss_scale_factor": null, "gradient_accumulation_steps": null, "beta_1": 0.9, "beta_2": 0.999, "epsilon": 1e-07, "amsgrad": false}}}}, "weightsManifest": [{"paths": ["group1-shard1of2.bin", "group1-shard2of2.bin"], "weights": [{"name": "sequential_33/batch_normalization_37/gamma", "shape": [32], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_37/beta", "shape": [32], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_37/moving_mean", "shape": [32], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_37/moving_variance", "shape": [32], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_38/gamma", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_38/beta", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_38/moving_mean", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_38/moving_variance", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_39/gamma", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_39/beta", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_39/moving_mean", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_39/moving_variance", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_40/gamma", "shape": [256], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_40/beta", "shape": [256], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_40/moving_mean", "shape": [256], "dtype": "float32"}, {"name": "sequential_33/batch_normalization_40/moving_variance", "shape": [256], "dtype": "float32"}, {"name": "sequential_33/conv2d_28/kernel", "shape": [3, 3, 1, 32], "dtype": "float32"}, {"name": "sequential_33/conv2d_28/bias", "shape": [32], "dtype": "float32"}, {"name": "sequential_33/conv2d_29/kernel", "shape": [3, 3, 32, 64], "dtype": "float32"}, {"name": "sequential_33/conv2d_29/bias", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/conv2d_30/kernel", "shape": [3, 3, 64, 64], "dtype": "float32"}, {"name": "sequential_33/conv2d_30/bias", "shape": [64], "dtype": "float32"}, {"name": "sequential_33/dense_62/kernel", "shape": [4096, 256], "dtype": "float32"}, {"name": "sequential_33/dense_62/bias", "shape": [256], "dtype": "float32"}, {"name": "sequential_33/dense_63/kernel", "shape": [256, 5], "dtype": "float32"}, {"name": "sequential_33/dense_63/bias", "shape": [5], "dtype": "float32"}]}]}
tflite/best_model.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:988615a6c6efe100a6f204282c7b9a3d28bd2f3eb71f903c2a19a558970a3879
3
+ size 1117480