open_nsfw接口封装成python脚本直接调用

脚本名称:getnsfwnum.py

import os
import sys
import commands

def index(filepath):
command = "python /home/open_nsfw/classify_nsfw.py --model_def /home/open_nsfw/nsfw_model/deploy.prototxt --pretrained_model /home/open_nsfw/nsfw_model/resnet_50_1by2_nsfw.caffemodel "+filepath
text = commands.getoutput(command)
num = text.find(‘NSFW score:’)
print text[num+14:num+28]

if name == “main”:
index(sys.argv[1])

效果如图:在这里插入图片描述
只需要后面加上文件路径就可以计算出此文件的值。
根据个人部署目录的不同,脚本需按实际情况进行修改。

猜你喜欢

转载自blog.csdn.net/goodsirlee/article/details/89312838