/ Модель

Характеристики

Контекст
77 токенов
Лицензия
Apache 2.0
Архитектура
clip · dense
Базовая модель
clip-vit-large-patch14
Библиотека
pytorch
Опубликована
16 июн 2025

clip-face-expression

Классификация изображенийИзображение → label3 профессии

Дообученная CLIP-модель классифицирует изображения лиц по семи выражениям эмоций и подходит для исследований и создания базовых систем распознавания выражений.

17скачиваний за 30 дней5лайковвеса обновлены16 июн 2025

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

syntheticbot/clip-face-expression — модель классификации изображений, дообученная на основе openai/clip-vit-large-patch14 для распознавания выражений лица. Разработчик заморозил визуальный энкодер CLIP и обучил линейную классификационную голову на датасете FER-2013. Модель относит изображение лица к одному из семи классов: злость, отвращение, страх, радость, нейтральное выражение, грусть и удивление. Репозиторий содержит веса safetensors для PyTorch; заявленная точность на тестовой выборке FER-2013 — 72%. Модель предназначена для исследовательских задач и использования как базовый ориентир при разработке систем распознавания выражений, например для анализа изображений в социальных исследованиях или вспомогательных приложениях. Лицензия — Apache-2.0.

Качество может различаться между демографическими группами из-за смещений FER-2013; модель обучалась преимущественно на фронтальных изображениях с выраженными эмоциями и может хуже работать на естественных, тонких или непрофильных выражениях. Предсказание по статичному изображению не является объективным определением эмоционального состояния человека. В README не рекомендуется применять модель для наблюдения или автоматических решений, существенно влияющих на людей.

Сценарии применения

  • классификация выражений лица на семь категорий эмоций
  • анализ выражения лица на изображениях для социальных исследований
  • оценка эмоций на фотографиях из пользовательского контента
  • создание базовой модели для экспериментов с распознаванием выражений лица

Ограничения

На FER-2013 заявлена точность 72%; смещения датасета по возрасту, полу и расе могут приводить к неодинаковому качеству. Модель хуже подходит для тонких, естественных и непрофильных выражений, а её прогноз не следует считать объективной оценкой эмоционального состояния.

Для каких профессий подходит3

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

CLIP-based Facial Expression Recognition (FER-2013)

This is a fine-tuned version of openai/clip-vit-large-patch14 for the task of Facial Expression Recognition (FER).

This model was trained on the FER-2013 dataset and can classify a facial image into one of seven emotions: angry, disgust, fear, happy, neutral, sad, and surprise. It was created using a transfer learning approach where the pre-trained CLIP vision encoder was frozen, and a new linear classification head was trained on top of it to recognize the emotion classes.

Model Description

  • Base Model: openai/clip-vit-large-patch14
  • Task: Image Classification (Facial Expression Recognition)
  • Framework: PyTorch
  • Dataset: FER-2013
  • Final Accuracy (Test Set): 72%

Intended Uses & Limitations

Intended Uses

This model is intended for academic research and as a baseline for developing more advanced emotion recognition systems. Potential applications include:

  • Analyzing sentiment in user-submitted media (e.g., product review videos).
  • Content analysis for social science research on emotion portrayal in images.
  • A building block for assistive technology applications.

Limitations and Bias

This model inherits the limitations of its training data, the FER-2013 dataset.

  • Dataset Bias: The FER-2013 dataset is known to have biases in its representation of age, gender, and race. As a result, the model's performance may be inconsistent across different demographic groups. It is not recommended for use in production systems that affect individuals without thorough bias evaluation and mitigation.
  • Posed vs. Natural Expressions: The dataset primarily contains posed, front-facing, and often exaggerated expressions. The model will likely perform worse on real-world images that feature subtle, natural, or non-frontal expressions.
  • Ambiguity of Emotion: Emotion is subjective and context-dependent. A static image cannot capture the full story. The model's predictions are based on learned visual patterns from the dataset and should not be considered an objective measure of a person's true emotional state.
  • Misuse Potential: This model should NOT be used for applications that involve making automated judgments about an individual's character, truthfulness, or employability. It is not suitable for surveillance or any application that could have a significant adverse impact on people's lives.

How to Use

To use this model, you first need to define its custom architecture, then load the saved weights from this repository.

1. Installation

pip install transformers torch safetensors Pillow huggingface_hub requests

2. Prediction Script

This runnable script downloads the model from this repository and predicts the emotion for an example image from the web.

import torch
import torch.nn as nn
from PIL import Image
from transformers import AutoProcessor, CLIPVisionModel
from safetensors.torch import load_file
import torch.nn.functional as F
from huggingface_hub import hf_hub_download
import requests

# --- Configuration ---
# This is the repository ID for the model on the Hugging Face Hub
REPO_ID = "syntheticbot/clip-face-expression" 
FILENAME = "model.safetensors"
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"

# The class names must be in alphabetical order as used during training
CLASS_NAMES = ['angry', 'disgust', 'fear', 'happy', 'neutral', 'sad', 'surprise']
NUM_CLASSES = len(CLASS_NAMES)

# --- Define the Model Architecture ---
# This class must be defined to match the architecture of the saved model
class ClipClassifier(nn.Module):
    def __init__(self, vision_model, num_classes):
        super(ClipClassifier, self).__init__()
        self.vision_model = vision_model
        # The base model's config is needed to get the hidden size for the classifier
        self.classifier = nn.Linear(vision_model.config.hidden_size, num_classes)

    def forward(self, pixel_values):
        outputs = self.vision_model(pixel_values=pixel_values)
        image_features = outputs.pooler_output
        logits = self.classifier(image_features)
        return logits

# --- Load Model and Processor ---
print("Loading model and processor...")
processor = AutoProcessor.from_pretrained("openai/clip-vit-large-patch14")
vision_model = CLIPVisionModel.from_pretrained("openai/clip-vit-large-patch14").to(DEVICE)

# Instantiate the custom classifier
model = ClipClassifier(vision_model, NUM_CLASSES).to(DEVICE)

# Download the model weights from the Hub and load them
print(f"Downloading model from {REPO_ID}...")
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
state_dict = load_file(model_path, device=DEVICE)
model.load_state_dict(state_dict)
model.eval()

# --- Run Prediction on an Example Image ---
# Example image from the web
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Carol_Burnett_1958.JPG/250px-Carol_Burnett_1958.JPG"
try:
    image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
except Exception as e:
    print(f"Could not load image from URL: {e}")
    exit()

print("Processing image and making prediction...")
with torch.no_grad():
    processed_image = processor(images=image, return_tensors="pt")['pixel_values'].to(DEVICE)
    logits = model(processed_image)
    probabilities = F.softmax(logits, dim=1)
    top_prob, top_idx = torch.max(probabilities, 1)
    predicted_class = CLASS_NAMES[top_idx.item()]

print(f"\nPredicted Emotion: {predicted_class}")
print(f"Confidence: {top_prob.item() * 100:.2f}%")

Training Procedure

The model was trained using a transfer learning approach. The openai/clip-vit-large-patch14 vision encoder was used as a frozen feature extractor. A single linear layer was added as a classification head and trained on the FER-2013 dataset.

Hyperparameters

  • Learning Rate: 1e-3
  • Batch Size: 128
  • Optimizer: Adam
  • Loss Function: Cross-Entropy Loss
  • Number of Epochs: 10

Evaluation Results

The model was evaluated on the FER-2013 test set, which contains 7,178 images.

Overall Accuracy: 72%

Classification Report

precisionrecallf1-scoresupport
angry0.670.620.65958
disgust0.680.640.66111
fear0.540.510.531024
happy0.890.930.911774
neutral0.680.740.711233
sad0.610.610.611247
surprise0.830.760.79831
accuracy0.727178
macro avg0.700.690.697178
weighted avg0.720.720.727178

Confusion Matrix

Confusion Matrix

Citation

Citing this Model

@misc{syntheticbot_2024_ferclip,
  author = {syntheticbot},
  title = {CLIP-based Facial Expression Recognition (FER-2013)},
  year = {2024},
  publisher = {Hugging Face},
  journal = {Hugging Face repository},
  howpublished = {\url{https://huggingface.co/syntheticbot/clip-face-expression}}
}

Citing the Original CLIP Model

@inproceedings{radford2021learning,
  title={Learning transferable visual models from natural language supervision},
  author={Radford, Alec and Kim, Jong Wook and Hallacy, Chris and Ramesh, Aditya and Goh, Gabriel and Agarwal, Sandhini and Sastry, Girish and Askell, Amanda and Mishkin, Pamela and Clark, Jack and others},
  booktitle={International conference on machine learning},
  pages={8748--8763},
  year={2021},
  organization={PMLR}
}

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · pytorch · image-classification

Можно запустить

Подбираем GPU…

Класс архитектуры
CLIPModel
Ревизия весов
861d115

0 моделей