根据下面库中提到的示例代码。我已经遵循了示例代码,但它没有工作。
[图书馆]https://github.com/notAI-tech/NudeNet/
from nudenet import NudeClassifier
import onnxruntime
classifier = NudeClassifier()
classifier.classify('/home/coremax/Downloads/DETECTOR_AUTO_GENERATED_DATA/IMAGES/3FEF7B75-3823-4153-8490-87483AAC6ABC'
'.jpg')
我也遵循了以前的StackOverflow解决方案,但它没有工作从ONNX运行超分辨率模型出错
Traceback (most recent call last):
File "/snap/pycharm-community/276/plugins/python-ce/helpers/pydev/pydevd.py", line 1491, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/snap/pycharm-community/276/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc)
File "/home/coremax/Documents/NudeNet/main.py", line 3, in <module>
classifier = NudeClassifier()
File "/home/coremax/Documents/NudeNet/nudenet/classifier.py", line 37, in __init__
self.nsfw_model = onnxruntime.InferenceSession(model_path)
File "/home/coremax/anaconda3/envs/AdultNET/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 158, in __init__
self._load_model(providers or [])
File "/home/coremax/anaconda3/envs/AdultNET/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 166, in _load_model
True)
RuntimeError: /onnxruntime_src/onnxruntime/core/session/inference_session.cc:238 onnxruntime::InferenceSession::InferenceSession(const onnxruntime::SessionOptions&, const onnxruntime::Environment&, const string&) status.IsOK() was false. Given model could not be parsed while creating inference session. Error message: Protobuf parsing failed.
我知道这太迟了,但希望这能帮助人们构建一个非常有用的软件。
为什么失败
错误是要使nudecclassifier工作,它必须从这个链接下载onnx模型
但是github现在要求你登录才能下载任何文件,所以nudecclassifier的构造函数在试图下载此模型时失败
<标题>解决方案在用户的主文件夹中创建一个名为
.NudeNet/
的文件夹从此链接下载模型
将模型保存在步骤1中创建的文件夹中
您现在应该在以下路径
拥有模型~/.NudeNet/classifier_model.onnx
现在你准备好了,祝你好运!
标题>