🚀 成人内容图像检测 - 卓越表现者
本模型针对成人内容图像分类进行了微调。它能将内容分为三个关键安全类别,适用于内容审核、安全过滤和合规内容处理系统。
https://exnrt.com/blog/ai/fine-tuning-siglip2/
🚀 快速开始
本模型可用于成人内容图像分类,将图像分为不同的安全类别。
✨ 主要特性
- 基于
google/siglip2-base-patch16-224
基础模型微调。
- 能够将图像内容分为三个关键安全类别,适用于内容审核、安全过滤和合规内容处理系统。
📦 安装指南
文档未提供安装步骤,可参考Hugging Face Transformers库的安装方法:
pip install transformers
💻 使用示例
基础用法
import torch
from transformers import AutoImageProcessor, SiglipForImageClassification
from PIL import Image
import torch.nn.functional as F
model_path = "Ateeqq/nsfw-image-detection"
processor = AutoImageProcessor.from_pretrained(model_path)
model = SiglipForImageClassification.from_pretrained(model_path)
image_path = r"/content/download.jpg"
image = Image.open(image_path).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
probabilities = F.softmax(logits, dim=1)
predicted_class_id = logits.argmax().item()
predicted_class_label = model.config.id2label[predicted_class_id]
confidence_scores = probabilities[0].tolist()
print(f"Predicted class ID: {predicted_class_id}")
print(f"Predicted class label: {predicted_class_label}\n")
for i, score in enumerate(confidence_scores):
label = model.config.id2label[i]
print(f"Confidence for '{label}': {score:.6f}")
输出示例
Predicted class ID: 2
Predicted class label: safe_normal
Confidence for 'gore_bloodshed_violent': 0.000002
Confidence for 'nudity_pornography': 0.000005
Confidence for 'safe_normal': 0.999993
📚 详细文档
模型详情
属性 |
详情 |
基础模型 |
google/siglip2-base-patch16-224 |
任务 |
图像分类(成人内容/安全检测) |
框架 |
PyTorch / Hugging Face Transformers |
微调数据集 |
包含3个内容类别的自定义数据集 |
选择的检查点 |
第5个epoch |
批量大小 |
64 |
训练轮数 |
5 |
混淆矩阵

分类类别
ID |
标签 |
排除情况 |
0 |
gore_bloodshed_violent |
打架、事故、愤怒场景 |
1 |
nudity_pornography |
正常的浪漫、亲吻场景 |
2 |
safe_normal |
无 |
标签映射
label2id = {'gore_bloodshed_violent': 0, 'nudity_pornography': 1, 'safe_normal': 2}
id2label = {0: 'gore_bloodshed_violent', 1: 'nudity_pornography', 2: 'safe_normal'}
训练指标(选择第5个epoch)
轮数 |
训练损失 |
验证损失 |
准确率 |
1 |
0.0765 |
0.1166 |
95.70% |
2 |
0.0719 |
0.0477 |
98.34% |
3 |
0.0089 |
0.0634 |
98.05% |
4 |
0.0109 |
0.0437 |
98.61% |
5 |
0.0001 |
0.0389 |
99.02% |
每轮训练结果

- 训练运行时间:1小时21分40秒
- 最终训练损失:0.0727
- 每秒步数:0.11 | 每秒样本数:6.99
📄 许可证
本项目采用Apache-2.0许可证。