[Error] OSError: image file is truncated

Hyun·2022년 7월 28일
0

ERROR

목록 보기
1/5

Error :

OSError: image file is truncated

img = image.load_img(name, target_size=(224, 224, 3))
img = image.img_to_array(img)		<--- x
plt.imshow(img.astype("uint8"))		<--- x
plt.axis("off")
...

원인

image파일을 다운 받다 중간에 중지해서 img가 잘리게(crop)되었다.

내 경우는 img파일을 다운 받다가 중간에 keyInterrupt를 발생시켜 데이터를 바로 저장하지 못해서 생겼던 것으로 보인다.

해결

: 다시 data 다운 받았다.

일반적인 해결 방법

keras.preporcessor.image.img_to_array 에서 image 다루는 소스를 보니 PIL.Image를 import하여 image를 다루는 것이었다.

그렇기 때문에

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

하면 된다!

  • img=image.img_to_array(img) == img=np.asarray(img)

출처: https://deep-deep-deep.tistory.com/34 [딥딥딥:티스토리]
keras docs

0개의 댓글