GantMan / nsfw_model

Keras model of NSFW detector
Other
1.75k stars 273 forks source link

244 - 299 problem #152

Open NasaKHw opened 8 months ago

NasaKHw commented 8 months ago

Hello

ValueError: Input 0 of layer "model_1" is incompatible with the layer: expected shape=(None, 299, 299, 3), found shape=(None, 224, 224, 3)

im sure that my images are 299 299 i also tried :

from nsfw_detector import predict model = predict.load_model('models/nsfw.299x299.h5') predict.classify(model, 'test/frames/', 299)

or

from nsfw_detector import predict model = predict.load_model('models/nsfw.299x299.h5')

Predict single image

predict.classify(model, 'test/frames/output_0045.jpg', 299)

output : :38] TF-TRT Warning: Could not find TensorRT test/frames/output_0045.jpg size: (299, 299) 1/1 [==============================] - 2s 2s/step [root@server-194-5-205-78 nsfw_model]#

but it did not print the result and only printed images name and , 299 thats all any trick to solve it ?

NasaKHw commented 8 months ago

u should write it like this and save it to outputfile to work but i dont know why is it considering a bird as sexy!!!

from nsfw_detector import predict

Load the model

model = predict.load_model('models/nsfw.299x299.h5')

Classify images and store the results

results = predict.classify(model, 'output_frames299', 299)

Define the path to the output text file

output_file = 'output_results.txt'

Open the file in write mode and write the results

with open(output_file, 'w') as f: for image_path, result in results.items(): f.write(f"Image: {image_path}\n") for category, probability in result.items(): f.write(f"{category}: {probability}\n") f.write("\n")

print(f"Output written to {output_file}")