notAI-tech / NudeNet

Lightweight nudity detection
https://nudenet.notai.tech/
GNU Affero General Public License v3.0
1.76k stars 342 forks source link

I got error on passing image url in classifier.classify()! #91

Open SohaibShafiq1 opened 3 years ago

SohaibShafiq1 commented 3 years ago

OSError: [Errno 22] Invalid argument: 'https://i.imgur.com/rga6845.jpg' What is the solution for that?

bedapudi6788 commented 3 years ago

Only local filepaths are supported. Download the image first and pass its path.

SohaibShafiq1 commented 3 years ago

No No, urls are supported too. image_bytes = io.BytesIO(image-url) image = Image.open(image_bytes) result=classifier.classify(image)

then: in .virtaulenv>(venv-name)>lib>site-packages>nudenet>image_utils.py>load_img

Previous: if isinstance(path, type("")): img = pil_image.open(path) else: path = cv2.cvtColor(path, cv2.COLOR_BGR2RGB) img = pil_image.fromarray(path)

Now: if isinstance(path, type("")): img = pil_image.open(np.array(path)) else: path = cv2.cvtColor(np.array(path), cv2.COLOR_BGR2RGB) img = pil_image.fromarray(path)

It worked.

SohaibShafiq1 commented 3 years ago

But if nudenet edit this from their end it will be good. Because when i will deploy the app, the actuall files be the files of nudenet not mine(image_utils.py file). So i wants to request the nudenet to update the code.

SohaibShafiq1 commented 3 years ago

I found the other solution as well. (image-url=The url of the image user wants to classify.) import numpy as np image_bytes = io.BytesIO(image-url) image = Image.open(image_bytes) result=classifier.classify(np.array(image)) It worked.