Image Classification
ONNX
timm
English
Chinese
efficientnet-v2-m
fp16
content-moderation
image-safety
Not-For-All-Audiences
Eval Results (legacy)
Instructions to use jiangchengchengNLP/image_l_class with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use jiangchengchengNLP/image_l_class with timm:
import timm model = timm.create_model("hf_hub:jiangchengchengNLP/image_l_class", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Image L-Class — 图片内容分级 (L1–L4)
基于 EfficientNet 的图片内容分级模型,支持 L1–L4 四级分类。
分类标准
| 等级 | 说明 | 示例 |
|---|---|---|
| L1 | 轻度性感内容 | 正常身材 + 性感内衣/衣物遮挡下体,姿势正常无性暗示 |
| L2 | 中度性感内容 | 夸张身材 + 衣着性感/较少,姿势有较强性暗示 |
| L3 | 重度性感内容 | 裸露(半裸/全裸),私密部位暴露 |
| L4 | 色情内容 | 明确性行为/性交内容 |
详细分级标准见 数据准备文档
当前版本:v1.0.1(推荐部署)
| 项目 | 值 |
|---|---|
| 版本 | v1.0.1 |
| 文件 | efficientNet/V2M/efficientNet-V2M-ema-fp16.onnx(同 v1.0.1 权重) |
| 版本归档 | efficientNet/V2M/efficientNet-V2M-ema-fp16-v1.0.1.onnx |
| 架构 | tf_efficientnetv2_m(timm) |
| 输入尺寸 | 384 × 384 |
| 精度 | FP16(ONNX 输入须 float16) |
| 权重 | EMA |
| 大小 | ~101 MB |
| 训练数据 | ~30.6K(Civitai 人工复核 + 线上复核 + ~4K qwen-image-edit) |
| 基座 | v1.0.0 权重 --resume 微调(40 epoch) |
| 定位 | L2 / L3 边界档加强 |
同集对比(data_20K_v3_split/val,5224 张 @384)
| 等级 | v1.0.0 | v1.0.1 | Δ |
|---|---|---|---|
| Overall | 92.99% | 94.08% | +1.09 |
| L1 Recall | 95.35% | 96.05% | +0.70 |
| L2 Recall | 86.67% | 88.30% | +1.63 |
| L3 Recall | 85.54% | 89.19% | +3.65 |
| L4 Recall | 96.69% | 96.86% | +0.17 |
变更摘要
- 在 v1.0.0 上
--resume微调,训练数据扩至 ~30.6K(含 ~4K qwen-image-edit 生图,人工复核) - 重点提升 L2 / L3 边界档
训练验证集(data_24K_v4_split/val,6113 张)
| 等级 | Precision | Recall | 样本数 |
|---|---|---|---|
| Overall | — | 96.52% | 6113 |
| L1 | 97.51% | 97.55% | 2124 |
| L2 | 92.53% | 93.65% | 913 |
| L3 | 96.45% | 94.88% | 1290 |
| L4 | 97.44% | 97.93% | 1786 |
与上表 5224 张为不同划分,Overall 不可直接对比。
ONNX Runtime 推理(V2M v1.0.1)
import onnxruntime as ort
import numpy as np
from PIL import Image
from torchvision import transforms
MODEL_PATH = "efficientNet/V2M/efficientNet-V2M-ema-fp16.onnx"
IMG_SIZE = 384
CLASS_NAMES = ["L1", "L2", "L3", "L4"]
session = ort.InferenceSession(MODEL_PATH, providers=["CPUExecutionProvider"])
input_name = session.get_inputs()[0].name
input_dtype = np.float16 # FP16 模型必须用 float16 喂入
transform = transforms.Compose([
transforms.Resize((IMG_SIZE, IMG_SIZE)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]),
])
img = Image.open("image.jpg").convert("RGB")
input_tensor = transform(img).unsqueeze(0).numpy().astype(input_dtype)
outputs = session.run(None, {input_name: input_tensor})[0]
pred_id = int(np.argmax(outputs, axis=1)[0])
print(f"预测等级: {CLASS_NAMES[pred_id]}")
推理服务(本地)
cd image_L_class_train/tools/inference_server
python app.py \
--model-path /path/to/efficientNet-V2M-ema-fp16.onnx \
--model-format onnx \
--img-size 384 \
--device cpu \
--port 6006
支持 file / files 上传,以及 JSON/form 字段 image_url。
历史版本:v1.0.0
| 项目 | 值 |
|---|---|
| 训练数据 | ~26K(Civitai 人工复核) |
| 验证集 | data_20K_v3_split/val,5224 张 |
| Overall Acc | 92.99% |
| 等级 | Acc | Precision | Recall | 样本数 |
|---|---|---|---|---|
| L1 | 95.35% | 94.48% | 95.35% | 1848 |
| L2 | 86.67% | 88.32% | 86.67% | 855 |
| L3 | 85.54% | 90.56% | 85.54% | 740 |
| L4 | 96.69% | 94.56% | 96.69% | 1781 |
历史模型:EfficientNet-B0(轻量版)
| 项目 | 值 |
|---|---|
| 文件 | efficientNet/B0/efficientNet-B0.onnx |
| 架构 | EfficientNet-B0 |
| 输入尺寸 | 224 × 224(Resize 256 + CenterCrop 224) |
| 精度 | FP32 |
| 大小 | ~14 MB |
分类精度(B0 基准)
| 等级 | 准确率 |
|---|---|
| Overall | 82.50% (n=1400) |
| L1 | 87.47% |
| L2 | 73.31% |
| L3 | 84.87% |
| L4 | 82.93% |
ONNX Runtime 推理(B0)
import onnxruntime as ort
import numpy as np
from PIL import Image
from torchvision import transforms
session = ort.InferenceSession("efficientNet/B0/efficientNet-B0.onnx")
input_name = session.get_inputs()[0].name
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]),
])
img = Image.open("image.jpg").convert("RGB")
input_tensor = transform(img).unsqueeze(0).numpy()
outputs = session.run(None, {input_name: input_tensor})[0]
pred_id = np.argmax(outputs, axis=1)[0]
class_names = ["L1", "L2", "L3", "L4"]
print(f"预测等级: {class_names[pred_id]}")
权重文件一览
| 路径 | 大小 | 说明 |
|---|---|---|
efficientNet/V2M/efficientNet-V2M-ema-fp16.onnx |
~101 MB | 当前部署:V2M EMA FP16 @384 v1.0.1 |
efficientNet/V2M/efficientNet-V2M-ema-fp16-v1.0.1.onnx |
~101 MB | v1.0.1 版本归档 |
efficientNet/B0/efficientNet-B0.onnx |
~14 MB | 历史轻量 FP32 @224 |
训练与继续微调
- 训练代码:image_L_class_train
- 框架:timm + PyTorch
- 线上 badcase 对齐 / 继续微调:见仓库内
docs/上线继续训练.md
部署建议
| 场景 | 建议 |
|---|---|
| 生产 | V2M FP16 @384 v1.0.1,ONNX Runtime |
| GPU | FP32 ONNX + CUDA(低延迟) |
| CPU | FP16 ONNX;可设 OMP_NUM_THREADS=32 |
| 轻量 | B0 FP32 @224 |
Model tree for jiangchengchengNLP/image_l_class
Base model
timm/tf_efficientnetv2_m.in21k_ft_in1kEvaluation results
- Accuracy on data_20K_v3_split/valimage_L_class_train output/9 benchmark.py94.080
- L2 Recall on data_20K_v3_split/valimage_L_class_train output/9 benchmark.py88.300
- L3 Recall on data_20K_v3_split/valimage_L_class_train output/9 benchmark.py89.190