OSError: image file is truncated (16 bytes not processed)

Posted zukang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OSError: image file is truncated (16 bytes not processed)相关的知识,希望对你有一定的参考价值。

Traceback (most recent call last):
2012   File "train.py", line 131, in <module>
2013     for _, (input_images, ground_truths, masks) in enumerate(data_loader):
2014   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
2015     data = self._next_data()
2016   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
2017     return self._process_data(data)
2018   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
2019     data.reraise()
2020   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/_utils.py", line 394, in reraise
2021     raise self.exc_type(msg)
2022 OSError: Caught OSError in DataLoader worker process 3.
2023 Original Traceback (most recent call last):
2024   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
2025     data = fetcher.fetch(index)
2026   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
2027     data = [self.dataset[idx] for idx in possibly_batched_index]
2028   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
2029     data = [self.dataset[idx] for idx in possibly_batched_index]
2030   File "/home/guoxiefan/PyTorch/ImageInpainting/LBAM/src/dataset.py", line 76, in __getitem__
2031     ground_truth = self.image_files_transforms(image.convert(\'RGB\'))
2032   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/PIL/Image.py", line 873, in convert
2033     self.load()
2034   File "/data/guoxiefan/anaconda3/envs/pytorch/lib/python3.6/site-packages/PIL/ImageFile.py", line 247, in load
2035     "(%d bytes not processed)" % len(b)
2036 OSError: image file is truncated (34 bytes not processed)

原因:有些图片太大,超出PIL的处理范围

参考解决方案:https://blog.csdn.net/scool_winter/article/details/89426509

解决方法:加上下面两行代码,这样在遇到截断的JPEG时,程序就会跳过去,读取另一张图片了

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

 

以上是关于OSError: image file is truncated (16 bytes not processed)的主要内容,如果未能解决你的问题,请参考以下文章

OSError: cannot identify image file

解决raise OSError(“Truncated File Read“)OSError: Truncated File Read

解决raise OSError(“Truncated File Read“)OSError: Truncated File Read

OSError:无法打开文件(无法打开文件)

OSError: [Errno 2] No such file or directory using pytesser

torch.cuda.is_available() OSError: [WinError 126]