🚀 成人內容圖像檢測 - 卓越表現者
本模型針對成人內容圖像分類進行了微調。它能將內容分為三個關鍵安全類別,適用於內容審核、安全過濾和合規內容處理系統。
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許可證。