CoolFace
Modelpublic

pollux435/mobilenet-v4-emotion

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes18downloads
Model Card

MobileNetV4 Emotion Recognition Model ๐ŸŽญ

FER2013 ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ ํ•™์Šต๋œ MobileNetV4 ๊ธฐ๋ฐ˜์˜ ๊ฐ์ • ์ธ์‹ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.

๋ชจ๋ธ ๊ฐœ์š”

์ด ๋ชจ๋ธ์€ MobileNetV4๋ฅผ ๋ฐฑ๋ณธ์œผ๋กœ ์‚ฌ์šฉํ•˜์—ฌ 7๊ฐ€์ง€ ๊ฐ์ •์„ ๋ถ„๋ฅ˜ํ•ฉ๋‹ˆ๋‹ค:

  • โ€”๐Ÿ˜  Angry (ํ™”๋‚จ)
  • โ€”๐Ÿคข Disgust (ํ˜์˜ค)
  • โ€”๐Ÿ˜จ Fear (๋‘๋ ค์›€)
  • โ€”๐Ÿ˜Š Happy (ํ–‰๋ณต)
  • โ€”๐Ÿ˜ข Sad (์Šฌํ””)
  • โ€”๐Ÿ˜ฒ Surprise (๋†€๋žŒ)
  • โ€”๐Ÿ˜ Neutral (๋ฌดํ‘œ์ •)

๋ชจ๋ธ ์•„ํ‚คํ…์ฒ˜

  • โ€”๋ฐฑ๋ณธ: MobileNetV4 (timm/mobilenetv4convmedium.e500r224in1k)
  • โ€”๋ถ„๋ฅ˜๊ธฐ: 3์ธต ์™„์ „์—ฐ๊ฒฐ์ธต (512 โ†’ 128 โ†’ 7)
  • โ€”์ •๊ทœํ™”: Batch Normalization + Dropout (0.5)
  • โ€”์ž…๋ ฅ ํฌ๊ธฐ: 224ร—224 RGB ์ด๋ฏธ์ง€

์„ฑ๋Šฅ

  • โ€”๊ฒ€์ฆ ์ •ํ™•๋„(test): 62.50% (FER2013 ๊ธฐ์ค€)
  • โ€”๋ชจ๋ธ ํฌ๊ธฐ: ์•ฝ 35MB
  • โ€”์ถ”๋ก  ์†๋„: batch=256์—์„œ 1.41it/s

์‚ฌ์šฉ ๋ฐฉ๋ฒ•

๋น ๋ฅธ ์‹œ์ž‘

python
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}")

์ „์ดํ•™์Šต

์ด ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ด์„œ ์‰ฝ๊ฒŒ ์ „์ดํ•™์Šต์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

python
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)

# ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋ฐ์ดํ„ฐ๋กœ ํ•™์Šตํ•˜์„ธ์š”!

์„ค์น˜ ์š”๊ตฌ์‚ฌํ•ญ

bash
pip install torch torchvision transformers timm pillow numpy

ํ•™์Šต ์ •๋ณด

  • โ€”๋ฐ์ดํ„ฐ์…‹: FER2013
  • โ€”ํ•™์Šต ๋ฐฉ๋ฒ•: 2๋‹จ๊ณ„ ํ•™์Šต
  • โ€”๋ถ„๋ฅ˜๊ธฐ๋งŒ ํ•™์Šต (10 ์—ํฌํฌ)
  • โ€”์ „์ฒด ๋„คํŠธ์›Œํฌ ๋ฏธ์„ธ์กฐ์ • (15 ์—ํฌํฌ)
  • โ€”์ตœ์ ํ™”: Adam ์˜ตํ‹ฐ๋งˆ์ด์ €
  • โ€”ํ•™์Šต๋ฅ :
  • โ€”๋ถ„๋ฅ˜๊ธฐ: 1e-3
  • โ€”๋ฐฑ๋ณธ: 1e-5 (๋ฏธ์„ธ์กฐ์ • ์‹œ)

๋ผ๋ฒจ ๋งคํ•‘

python
{
  "0": "angry",
  "1": "disgust", 
  "2": "fear",
  "3": "happy",
  "4": "sad",
  "5": "surprise",
  "6": "neutral"
}

์˜ˆ์ œ ๊ฒฐ๊ณผ

์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ˆ์ธก ๊ฐ์ •์‹ ๋ขฐ๋„
๐Ÿ˜ŠHappy0.89
๐Ÿ˜ขSad0.76
๐Ÿ˜ Angry0.82

์ธ์šฉ

์ด ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์‹ค ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ธ์šฉํ•ด ์ฃผ์„ธ์š”:

bibtex
@misc{mobilenetv4-emotion-2024,
  title={MobileNetV4 Based Emotion Recognition Model},
  author={pollux435},
  year={2024},
  publisher={Hugging Face},
  note={Trained on FER2013 dataset}
}

๋ผ์ด์„ ์Šค

MIT License