Views
No views yet
1from transformers import AutoConfig
2from modeling_mobilenet_v4_emotion import MobileNetV4EmotionClassifier
3from preprocessing import preprocess_image
4import torch
5
6# 모델 로드
7config = AutoConfig.from_pretrained("pollux435/mobilenet-v4-emotion", trust_remote_code=True)
8model = MobileNetV4EmotionClassifier.from_pretrained("pollux435/mobilenet-v4-emotion", trust_remote_code=True)
9model.eval()
10
11# 이미지 예측
12image_path = "your_image.jpg"
13pixel_values = preprocess_image(image_path)
14
15with torch.no_grad():
16 outputs = model(pixel_values)
17 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
18
19predicted_class_id = outputs.logits.argmax().item()
20predicted_emotion = config.id2label[str(predicted_class_id)]
21confidence = probabilities[0][predicted_class_id].item()
22
23print(f"예측된 감정: {predicted_emotion}")
24print(f"신뢰도: {confidence:.4f}")1from transformers import AutoConfig
2from modeling_mobilenet_v4_emotion import MobileNetV4EmotionClassifier
3
4# 기존 모델 로드
5model = MobileNetV4EmotionClassifier.from_pretrained("pollux435/mobilenet-v4-emotion", trust_remote_code=True)
6
7# 새로운 클래스 수로 분류기 교체 (예: 3개 클래스)
8import torch.nn as nn
9in_features = model.classifier[-1].in_features
10model.classifier[-1] = nn.Linear(in_features, 3)
11
12# 이제 여러분의 데이터로 학습하세요!pip install torch torchvision transformers timm pillow numpy1{
2 "0": "angry",
3 "1": "disgust",
4 "2": "fear",
5 "3": "happy",
6 "4": "sad",
7 "5": "surprise",
8 "6": "neutral"
9}| 입력 이미지 | 예측 감정 | 신뢰도 |
|---|---|---|
| 😊 | Happy | 0.89 |
| 😢 | Sad | 0.76 |
| 😠 | Angry | 0.82 |
1@misc{mobilenetv4-emotion-2024,
2 title={MobileNetV4 Based Emotion Recognition Model},
3 author={pollux435},
4 year={2024},
5 publisher={Hugging Face},
6 note={Trained on FER2013 dataset}
7}