Pytorch-yolov3: OSError: image file is truncated (7 bytes not processed)

Created on 7 May 2019  路  4Comments  路  Source: eriklindernoren/PyTorch-YOLOv3

It seems there is still some problem with Image loader.

 File "...\PyTorch-YOLOv3\utils\datasets.py", line 86, in __getitem__
    img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))
  File "C:\ProgramData\Anaconda3\envs\ghimire\lib\site-packages\PIL\Image.py", line 899, in convert
    self.load()
  File "C:\ProgramData\Anaconda3\envs\ghimire\lib\site-packages\PIL\ImageFile.py", line 236, in load
    len(b))
OSError: image file is truncated (7 bytes not processed)

Therefore i'm using cv2 image loader.

Most helpful comment

It's probably you installed Pillow instead of PIL. Try adding these to datasets.py file at line 14:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

All 4 comments

It's probably you installed Pillow instead of PIL. Try adding these to datasets.py file at line 14:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

It's probably you installed Pillow instead of PIL. Try adding these to datasets.py file at line 14:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

@chuong , Solved

Thank you

The method about:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

is ineffective to me, so I change the code:
img = transforms.ToTensor()(Image.open(img_path).convert('RGB'))
to this:
img = transforms.ToTensor()(cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB))
and it works.

Thinks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhaowt61 picture zhaowt61  路  4Comments

qilong-zhang picture qilong-zhang  路  5Comments

qianwangn picture qianwangn  路  3Comments

0merjavaid picture 0merjavaid  路  4Comments

MessiahChen picture MessiahChen  路  3Comments