While passing a folder of images to a ML-script, I'll receive an error, maybe caused by a broken image:
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001C3BB0AAEA0>
My code:
for files in Files:
if files.endswith(".jpg"):
image_name = files
image_check = image.load_img(image_name, target_size=(1200,1600))
images = image.img_to_array(image_check)
images = np.expand_dims(images, axis=0)
prediction = np.argmax(model.predict(images), axis=-1)
The script stops running, whenever this error occurs. Is it possible to just skip the according file and move over?
Thanks!