MobileNetV4 Emotion Recognition Model ๐ญ
FER2013 ๋ฐ์ดํฐ์ ์ผ๋ก ํ์ต๋ MobileNetV4 ๊ธฐ๋ฐ์ ๊ฐ์ ์ธ์ ๋ชจ๋ธ์ ๋๋ค.
๋ชจ๋ธ ๊ฐ์
์ด ๋ชจ๋ธ์ MobileNetV4๋ฅผ ๋ฐฑ๋ณธ์ผ๋ก ์ฌ์ฉํ์ฌ 7๊ฐ์ง ๊ฐ์ ์ ๋ถ๋ฅํฉ๋๋ค:
- ๐ Angry (ํ๋จ)
- ๐คข Disgust (ํ์ค)
- ๐จ Fear (๋๋ ค์)
- ๐ Happy (ํ๋ณต)
- ๐ข Sad (์ฌํ)
- ๐ฒ Surprise (๋๋)
- ๐ Neutral (๋ฌดํ์ )
๋ชจ๋ธ ์ํคํ ์ฒ
- ๋ฐฑ๋ณธ: MobileNetV4 (timm/mobilenetv4_conv_medium.e500_r224_in1k)
- ๋ถ๋ฅ๊ธฐ: 3์ธต ์์ ์ฐ๊ฒฐ์ธต (512 โ 128 โ 7)
- ์ ๊ทํ: Batch Normalization + Dropout (0.5)
- ์ ๋ ฅ ํฌ๊ธฐ: 224ร224 RGB ์ด๋ฏธ์ง
์ฑ๋ฅ
- ๊ฒ์ฆ ์ ํ๋(test): 62.50% (FER2013 ๊ธฐ์ค)
- ๋ชจ๋ธ ํฌ๊ธฐ: ์ฝ 35MB
- ์ถ๋ก ์๋: batch=256์์ 1.41it/s
์ฌ์ฉ ๋ฐฉ๋ฒ
๋น ๋ฅธ ์์
from transformers import AutoConfig
from modeling_mobilenet_v4_emotion import MobileNetV4EmotionClassifier
from preprocessing import preprocess_image
import torch
# ๋ชจ๋ธ ๋ก๋
config = AutoConfig.from_pretrained("pollux435/mobilenet-v4-emotion", trust_remote_code=True)
model = MobileNetV4EmotionClassifier.from_pretrained("pollux435/mobilenet-v4-emotion", trust_remote_code=True)
model.eval()
# ์ด๋ฏธ์ง ์์ธก
image_path = "your_image.jpg"
pixel_values = preprocess_image(image_path)
with torch.no_grad():
outputs = model(pixel_values)
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_class_id = outputs.logits.argmax().item()
predicted_emotion = config.id2label[str(predicted_class_id)]
confidence = probabilities[0][predicted_class_id].item()
print(f"์์ธก๋ ๊ฐ์ : {predicted_emotion}")
print(f"์ ๋ขฐ๋: {confidence:.4f}")
์ ์ดํ์ต
์ด ๋ชจ๋ธ์ ์ฌ์ฉํด์ ์ฝ๊ฒ ์ ์ดํ์ต์ ํ ์ ์์ต๋๋ค:
from transformers import AutoConfig
from modeling_mobilenet_v4_emotion import MobileNetV4EmotionClassifier
# ๊ธฐ์กด ๋ชจ๋ธ ๋ก๋
model = MobileNetV4EmotionClassifier.from_pretrained("pollux435/mobilenet-v4-emotion", trust_remote_code=True)
# ์๋ก์ด ํด๋์ค ์๋ก ๋ถ๋ฅ๊ธฐ ๊ต์ฒด (์: 3๊ฐ ํด๋์ค)
import torch.nn as nn
in_features = model.classifier[-1].in_features
model.classifier[-1] = nn.Linear(in_features, 3)
# ์ด์ ์ฌ๋ฌ๋ถ์ ๋ฐ์ดํฐ๋ก ํ์ตํ์ธ์!
์ค์น ์๊ตฌ์ฌํญ
pip install torch torchvision transformers timm pillow numpy
ํ์ต ์ ๋ณด
- ๋ฐ์ดํฐ์ : FER2013
- ํ์ต ๋ฐฉ๋ฒ: 2๋จ๊ณ ํ์ต
- ๋ถ๋ฅ๊ธฐ๋ง ํ์ต (10 ์ํฌํฌ)
- ์ ์ฒด ๋คํธ์ํฌ ๋ฏธ์ธ์กฐ์ (15 ์ํฌํฌ)
- ์ต์ ํ: Adam ์ตํฐ๋ง์ด์
- ํ์ต๋ฅ :
- ๋ถ๋ฅ๊ธฐ: 1e-3
- ๋ฐฑ๋ณธ: 1e-5 (๋ฏธ์ธ์กฐ์ ์)
๋ผ๋ฒจ ๋งคํ
{
"0": "angry",
"1": "disgust",
"2": "fear",
"3": "happy",
"4": "sad",
"5": "surprise",
"6": "neutral"
}
์์ ๊ฒฐ๊ณผ
| ์ ๋ ฅ ์ด๋ฏธ์ง | ์์ธก ๊ฐ์ | ์ ๋ขฐ๋ |
|---|---|---|
| ๐ | Happy | 0.89 |
| ๐ข | Sad | 0.76 |
| ๐ | Angry | 0.82 |
์ธ์ฉ
์ด ๋ชจ๋ธ์ ์ฌ์ฉํ์ค ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ์ธ์ฉํด ์ฃผ์ธ์:
@misc{mobilenetv4-emotion-2024,
title={MobileNetV4 Based Emotion Recognition Model},
author={pollux435},
year={2024},
publisher={Hugging Face},
note={Trained on FER2013 dataset}
}
๋ผ์ด์ ์ค
MIT License
- Downloads last month
- 4