Open wanghaifengnihaoa opened 1 year ago
i have the same error lol
made a new venv python 3.10.9
installed requirements
then installed
Successfully installed protobuf-3.20.2
(venv) F:\768 1024 realistic man class dataset\nsfw_model>python fix.py
F:\768 1024 realistic man class dataset\raw\00000-102817736.png size: (224, 224)
Traceback (most recent call last):
File "F:\768 1024 realistic man class dataset\nsfw_model\fix.py", line 31, in <module>
main(source_folder, dest_folder, model_path)
File "F:\768 1024 realistic man class dataset\nsfw_model\fix.py", line 24, in main
if filename.lower().endswith(('.png', '.jpg', '.jpeg')) and is_nsfw(file_path, model):
File "F:\768 1024 realistic man class dataset\nsfw_model\fix.py", line 7, in is_nsfw
pred = predict.classify(model, img_path)
File "F:\768 1024 realistic man class dataset\nsfw_model\nsfw_detector\predict.py", line 67, in classify
probs = classify_nd(model, images, predict_args)
File "F:\768 1024 realistic man class dataset\nsfw_model\nsfw_detector\predict.py", line 77, in classify_nd
model_preds = model.predict(nd_images, **predict_args)
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\King\AppData\Local\Temp\__autograph_generated_filej3ztbmn8.py", line 15, in tf__predict_function
retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
ValueError: in user code:
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\engine\training.py", line 2169, in predict_function *
return step_function(self, iterator)
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\engine\training.py", line 2155, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\engine\training.py", line 2143, in run_step **
outputs = model.predict_step(data)
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\engine\training.py", line 2111, in predict_step
return self(x, training=False)
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "F:\768 1024 realistic man class dataset\nsfw_model\venv\lib\site-packages\keras\engine\input_spec.py", line 298, in assert_input_compatibility
raise ValueError(
ValueError: Input 0 of layer "model_1" is incompatible with the layer: expected shape=(None, 299, 299, 3), found shape=(None, 224, 224, 3)
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3)
I doublechecked that image.shape is (224, 224, 3)
I'm running predict.classify_nd(model, image)
Puzzled. Did either of you ever figure this out? It seems to work fine for me if I run it on a file from the local filesystem, but I need to run from bytearrays, so I'm converting via PIL to numpy and I'm having trouble figuring out what it's trying to do that's mangling the shape.
usage example:
# Predict single image with nsfw.299x299.h5
model = predict.load_model('./nsfw.299x299.h5')
predict.classify(model, '2.jpg', 299)
# {'2.jpg': {'sexy': 4.3454795e-05, 'neutral': 0.00026579312, 'porn': 0.0007733498, 'hentai': 0.14751942, 'drawings': 0.8513979}, '6.jpg': {'drawings': 0.004214506, 'hentai': 0.013342537, 'neutral': 0.01834045, 'porn': 0.4431829, 'sexy': 0.5209196}}
I've added a usage example in the readme with pr https://github.com/GantMan/nsfw_model/pull/141
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3)
I doublechecked that image.shape is (224, 224, 3)
I'm running
predict.classify_nd(model, image)
Puzzled. Did either of you ever figure this out? It seems to work fine for me if I run it on a file from the local filesystem, but I need to run from bytearrays, so I'm converting via PIL to numpy and I'm having trouble figuring out what it's trying to do that's mangling the shape.
have you found the solution for, i am having same issue
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3)
I doublechecked that image.shape is (224, 224, 3) I'm runningpredict.classify_nd(model, image)
Puzzled. Did either of you ever figure this out? It seems to work fine for me if I run it on a file from the local filesystem, but I need to run from bytearrays, so I'm converting via PIL to numpy and I'm having trouble figuring out what it's trying to do that's mangling the shape.have you found the solution for, i am having same issue
got it, changed the img to be predicted from tuple to list
use:nsfw-predict --saved_model_path ./nsfw.299x299.h5 --image_source images/色情1-2.jpeg
but:
get shape:
is: