😐 VGG-Style 표정 분류 (FER) 모델

이 모델은 7가지 사람의 감정(표정)을 분류하기 위해 설계된 커스텀 VGG 스타일 합성곱 신경망(CNN) 모델입니다. 다양한 하이퍼파라미터 튜닝과 스케줄러 실험을 통해 최적화되었으며, 추가 데이터 학습 없이 Kaggle FER-2013 데이터셋 만으로 검증 데이터셋에서 "70.55%"의 정확도를 달성했습니다.

📝 모델 개요 (Model Details)

  • 모델 구조: Custom VGG-like CNN (4개의 Conv 블록 + 3개의 Linear 레이어)
  • 입력 크기: 48x48 픽셀 (흑백/Grayscale)
  • 분류 클래스: 7개 (Angry, Disgust, Fear, Happy, Sad, Surprise, Neutral)
  • 프레임워크: PyTorch
  • 학습 데이터: FER-2013

🏗️ 아키텍처 설명 (Architecture)

이 모델은 48x48 크기의 작은 이미지를 효과적으로 처리하기 위해 VGG 네트워크를 경량화하여 설계했습니다.

  • 특징 추출기 (Feature Extractor): (Conv -> BN -> ReLU) x 2 -> MaxPool 구조가 4번 반복되며 이미지의 특징을 깊이 있게 추출합니다.
  • 분류기 (Classifier): 추출된 특징을 평탄화(Flatten)한 후, 4096개의 노드를 가진 완전 연결 계층(Fully Connected Layer)을 거쳐 최종 7개의 감정으로 분류합니다.
  • 규제 (Regularization): 과적합 방지를 위해 Dropout(0.2)과 배치 정규화(Batch Normalization)를 모든 계층에 적용했습니다.

📊 성능 및 실험 결과 (Performance)

여러 초기 학습률(Learning Rate)과 스케줄러 설정을 비교 실험하여 최적의 값을 찾았습니다.

지표 (Metric) 점수 (Score) 비고
검증 정확도 (Val Accuracy) 70.55% Best Model
Patience 설정 3 ReduceLROnPlateau 최적값
초기 학습률 (Initial LR) 0.04 실험결과 가장 높은 성능 기록

💡 실험 노트: 초기 학습률을 0.01~0.05 사이에서 실험한 결과 0.04에서 가장 높은 성능을 보였으며, ReduceLROnPlateau 스케줄러의 Patience를 3으로 설정했을 때 학습 정체 구간을 가장 효율적으로 돌파하며 Global Minimum에 도달했습니다.

⚙️ 학습 설정 (Training Config)

  • Optimizer: SGD (Adam과 비교실험 진행함)
  • Loss Function: CrossEntropyLoss
  • Scheduler: ReduceLROnPlateau (mode='max', factor=0.1, patience=3, min_lr=1e-6)
  • Batch Size: 128
  • Preprocessing: - Resize(48x48)
    • Grayscale
    • Normalize((0.5,), (0.5,))

💻 사용 방법 (Usage)

PyTorch를 사용하여 모델을 로드하고 추론하는 예시 코드입니다.

import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import transforms
from PIL import Image

# 1. 모델 클래스 정의 (학습 코드와 동일)
class Vgg(nn.Module):
    def __init__(self, drop=0.2):
        super().__init__()
        # ... (모델 코드 생략, 학습 코드의 class Vgg 복사해서 넣으세요) ...
        # (Github에는 전체 코드를 파일로 올리는 것이 좋습니다)

# 2. 모델 불러오기
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = Vgg()

# Hugging Face 또는 로컬에서 가중치 로드
# model.load_state_dict(torch.load("pytorch_model.pth", map_location=device))
model.to(device)
model.eval()

# 3. 이미지 추론 예시
def predict_emotion(image_path):
    # 학습 때와 동일한 전처리 적용
    transform = transforms.Compose([
        transforms.Resize((48, 48)),
        transforms.Grayscale(num_output_channels=1),
        transforms.ToTensor(),
        transforms.Normalize((0.5,), (0.5,))
    ])
    
    image = Image.open(image_path)
    image = transform(image).unsqueeze(0).to(device)
    
    with torch.no_grad():
        output = model(image)
        _, predicted = torch.max(output, 1)
        
    emotions = ['Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral']
    return emotions[predicted.item()]

# print(predict_emotion("test_face.jpg"))
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support