2

According to the example code mentioned below the library. I have followed the example code but it didn't work.

[Library] https://github.com/notAI-tech/NudeNet/

Code

from nudenet import NudeClassifier
import onnxruntime
classifier = NudeClassifier()

classifier.classify('/home/coremax/Downloads/DETECTOR_AUTO_GENERATED_DATA/IMAGES/3FEF7B75-3823-4153-8490-87483AAC6ABC'
                    '.jpg')

I have also followed the previous solution on StackOverflow but it didn't work Error on running Super Resolution Model from 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.
Khawar Islam
  • 2,556
  • 2
  • 34
  • 56

1 Answers1

0

I know it is too late but hope this helps someone build a very useful software.

why it fails

the error is that for NudeClassifier to work it has to download the onnx model from this link

but github now requires you to be logged in to download any file so the constructor for the NudeClassifier fails as it tries to download this model

Solution

  1. create a folder in your user's home folder with the name .NudeNet/

  2. download the model from this link

  3. save the model in the folder you created in step one

  4. you should now have the model at the following path ~/.NudeNet/classifier_model.onnx

now you're ready to go good luck!