NudeNet icon indicating copy to clipboard operation
NudeNet copied to clipboard

Cannot import name 'NudeDetector' from 'nudenet'

Open remi1771 opened this issue 1 year ago • 1 comments

Hey there! I'm interested in creating a GUI for this program, so first things first I tried was testing it. While NudeClassifier works (albeit I had to pip install NudeNetClassifier(2.1.1), whenever I try to run the second part it crashes into Cannot import name 'NudeDetector' from 'nudenet'. My code is as follows

import onnxruntime
onnxruntime.get_device()
from nudenet import NudeClassifier
from nudenet import NudeDetector
from glob import glob
classifier = NudeClassifier()

# Update the glob function calls with the full path to your folder destination
with open('output.txt', 'w') as file:
    for image_path in glob('D:\\Other Drives Backups Etc\\64GB Transfer Allin1 to PC\\Roll\\*jpg') + \
                      globs
        output = f"{image_path} UNSAFE confidence: {classifier.classify(image_path)[image_path]['unsafe']}\n"
        file.write(output)



detector = NudeDetector()

# Update the glob function calls with the full path to your folder destination
with open('output.txt', 'a') as file:
    for image_path in glob('D:\\Other Drives Backups Etc\\64GB Transfer Allin1 to PC\\Roll\\*jpg') + \
                      globs):
        output = f"{image_path} detected parts: {detector.detect(image_path)}\n"
        file.write(output)

print("finished!")

remi1771 avatar Jul 29 '24 05:07 remi1771

Over a month old so I assume you probably got this working. But responding for anyone else facing this issue.

from nudenet.nudenet import NudeDetector

You likely need to do that given the folder structure of the project. I assume you did a git clone from your project root directory. The repo is structure with a subdirectory named nudenet that contains a python file nudenet.py. The nudenet.nudenet tells python to look in a folder called nudenet for a python file named nudenet and import an object/class/function name NudeDetector.

ratbunch avatar Aug 24 '24 04:08 ratbunch