基于 Freepik/nsfw_image_detector 的昇腾 NPU(Ascend 910 / torch-npu)适配。
TimmWrapperForImageClassification(timm_wrapper)eva02_base_patch14_448,输入 448x448neutral / low / medium / high)npu:0,已完全移除 CUDA 依赖transformers、timm、pillow、fastapi、uvicornexport 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}
}uvicorn inference:app --host 0.0.0.0 --port 8000
curl -F "file=@test_input.jpg" http://127.0.0.1:8000/predictinference.py — 双模式推理脚本(CLI + FastAPI),NPU 初始化 + 模型迁移 npu:0requirements.txt — 依赖清单model_weights/ — 本地权重缓存(不入库)assets/ — 适配验证截图(NPU 环境日志、CLI 推理、API 返回)