许可证:Apache-2.0
语言:
- 英文
基础模型:
- google/siglip2-base-patch16-224
任务类型:图像分类
库名称:transformers
标签:
- NSFW(不适宜工作场所内容)
- exnrt.com
NSFW图像检测——顶级性能模型
本模型专为NSFW图像分类微调,可将内容划分为三个安全关键类别,适用于内容审核、安全过滤及合规内容处理系统。
https://exnrt.com/blog/ai/fine-tuning-siglip2/
üöÄ 使用示例
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"预测类别ID: {predicted_class_id}")
print(f"预测类别标签: {predicted_class_label}\n")
for i, score in enumerate(confidence_scores):
label = model.config.id2label[i]
print(f"'{label}'置信度: {score:.6f}")
输出示例
预测类别ID: 2
预测类别标签: safe_normal
'gore_bloodshed_violent'置信度: 0.000002
'nudity_pornography'置信度: 0.000005
'safe_normal'置信度: 0.999993
ü߆ 模型详情
- 基础模型:
google/siglip2-base-patch16-224
- 任务: 图像分类(NSFW/安全内容检测)
- 框架: PyTorch / Hugging Face Transformers
- 微调数据集: 包含3类内容的定制数据集
- 选定检查点: 第5轮训练
- 批大小: 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轮‚úÖ)
训练轮数 |
训练损失 |
验证损失 |
准确率 |
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