随着现在应用内图片越来越多,安全审查也是必不可少的一个操作了
下面手把手教你如何将huggingface中的黄图检测模型部署到自己的服务器上去
1.找到对应的模型 nsfw_image_detection
2.在本地先验证如何使用
首先安装transformers python库
pip install transformers(用于导入ai模型,运行ai模型)
安装机器学习库
pip install torch
安装PIL库
pip install Pillow(用于将图片加载到内存供模型识别)
将上面网址对应里面的示例代码运行
from PIL import Image
from transformers import pipeline
img = Image.open("<path_to_image_file>")
classifier = pipeline("image-classification", model="Falconsai/nsfw_image_detection")
classifier(img)
发现可以出结果,那制作镜像就按照上述的逻辑做了
3.制作Dockerfile文件
FROM python:3.9-slim
WORKDIR /app
RUN echo "deb http://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free" > /etc/