gcw_mXoV1I2Z/Freepik-nsfw_image_detector
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Freepik/nsfw_image_detector — 昇腾 NPU 适配版

基于 Freepik/nsfw_image_detector 的昇腾 NPU(Ascend 910 / torch-npu)适配。

  • 模型类型: TimmWrapperForImageClassification(timm_wrapper)
  • Backbone: eva02_base_patch14_448,输入 448x448
  • 分类数: 4(neutral / low / medium / high)
  • 设备: npu:0,已完全移除 CUDA 依赖

环境

  • CANN ≥ 8.0,PyTorch 2.9.0 + torch_npu 2.9.0.post1
  • transformers、timm、pillow、fastapi、uvicorn

使用

CLI 推理

export ASCEND_VISIBLE_DEVICES=14
python inference.py --img test_input.jpg

输出 JSON 示例:

{
  "device": "npu:0",
  "model": "Freepik/nsfw_image_detector",
  "predicted_label": "low",
  "confidence": 0.953166,
  "class_probabilities": {"neutral": 0.0339, "low": 0.9532, "medium": 0.0075, "high": 0.0054}
}

FastAPI 服务

uvicorn inference:app --host 0.0.0.0 --port 8000
curl -F "file=@test_input.jpg" http://127.0.0.1:8000/predict

文件

  • inference.py — 双模式推理脚本(CLI + FastAPI),NPU 初始化 + 模型迁移 npu:0
  • requirements.txt — 依赖清单
  • model_weights/ — 本地权重缓存(不入库)
  • assets/ — 适配验证截图(NPU 环境日志、CLI 推理、API 返回)