ONNX Model Zoo

n4xtan/nsfw-classification

By n4xtan · ↓ 0 · ♥ 0 · Updated 2025-12-27

What's in this repo

This page lists the files in n4xtan/nsfw-classification, including nsfw_model.onnx.

  • 1 ONNX models (.onnx files)
  • 6 files, including 2 .json, 1 .md, 1 .onnx, 1 .txt
  • Last updated 2025-12-27

ONNX files

File Size Download
nsfw_model.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

NSFW Image Classifier

A CLIP-based image classification API that categorizes images into three classes: Safe, NSFW Mild, and NSFW Explicit.

Model Architecture

  • Backbone: OpenAI CLIP ViT-Large/14 (openai/clip-vit-large-patch14)
  • Classifier Head: Linear(1024, hidden_dim=1024) → ReLU → Dropout(0.5) → Linear(1024, 3)
  • Training Strategy: Two-phase fine-tuning (frozen backbone → full fine-tuning)
  • Dataset: 100K+ images with balanced class distribution
  • Validation Accuracy: ~97%

API Endpoints

Health Check

GET /health

Returns model status and configuration.

Single Prediction

POST /predict
Content-Type: multipart/form-data

Form field: image (file)

Response:

{
  "filename": "image.jpg",
  "predicted_class": "Safe",
  "predicted_index": 0,
  "is_nsfw": false,
  "confidence": 0.95,
  "all_scores": {
    "Safe": 0.95,
    "NSFW Mild": 0.03,
    "NSFW Explicit": 0.02
  },
  "status": "success"
}

Batch Prediction

POST /predict/batch
Content-Type: multipart/form-data

Form field: images (multiple files)

Preprocessing

Images are preprocessed with CLIP-specific normalization:

  • Resize to 224x224 (bicubic interpolation)
  • Center crop
  • Normalize with mean [0.481, 0.458, 0.408] and std [0.269, 0.261, 0.276]

Local Development

# Install dependencies
pip install -r requirements.txt

# Run the API
python app.py

The API runs on port 7860 by default. Override with the PORT environment variable.

Docker Deployment

docker build -t nsfw-classifier .
docker run -p 7860:7860 nsfw-classifier

The model is automatically downloaded from Hugging Face Hub on startup.

Example Usage

import requests

with open("image.jpg", "rb") as f:
    response = requests.post(
        "http://localhost:7860/predict",
        files={"image": f}
    )
print(response.json())

Configuration Reference

See Hugging Face Spaces Config Reference for deployment options.

Model info

onnx license:apache-2.0 region:us not-for-all-audiences
↓ 0 ♥ 0

Created: 2025-12-03

Updated: 2025-12-27

View on Hugging Face

Files (6)

.gitattributes
README.md
global_config.json
model_config.json
nsfw_model.onnx ONNX
requirements.txt

Related models