question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Could not load "" Reason: "image file is truncated"

See original GitHub issue

Hello, I am in trouble when I run the 5_evaluation_bop_basic.py file. The error is:

Recognizing scene_id:9, im_id:242
Recognizing scene_id:9, im_id:243
Traceback (most recent call last):
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/PIL/ImageFile.py", line 235, in load
    s = read(self.decodermaxblock)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/PIL/PngImagePlugin.py", line 659, in load_read
    cid, pos, length = self.png.read()
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/PIL/PngImagePlugin.py", line 122, in read
    length = i32(s)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/PIL/_binary.py", line 82, in i32be
    return unpack_from(">I", c, o)[0]
struct.error: unpack_from requires a buffer of at least 4 bytes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/plugins/pillow.py", line 671, in pil_try_read
    im.getdata()[0]
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/PIL/Image.py", line 1304, in getdata
    self.load()
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/PIL/ImageFile.py", line 241, in load
    raise IOError("image file is truncated")
OSError: image file is truncated

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Pix2Pose/tools/5_evaluation_bop_basic.py", line 261, in <module>
    image_t = inout.load_im(rgb_path)            
  File "./bop_toolkit/bop_toolkit_lib/inout.py", line 22, in load_im
    im = imageio.imread(path)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/core/functions.py", line 264, in imread
    reader = read(uri, format, "i", **kwargs)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/core/functions.py", line 186, in get_reader
    return format.get_reader(request)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/core/format.py", line 164, in get_reader
    return self.Reader(self, request)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/core/format.py", line 214, in __init__
    self._open(**self.request.kwargs.copy())
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/plugins/pillow.py", line 300, in _open
    return PillowFormat.Reader._open(self, pilmode=pilmode, as_gray=as_gray)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/plugins/pillow.py", line 137, in _open
    pil_try_read(self._im)
  File "/home/anaconda3/envs/pix2pose/lib/python3.6/site-packages/imageio/plugins/pillow.py", line 682, in pil_try_read
    raise ValueError(error_message)
ValueError: Could not load "" 
Reason: "image file is truncated"
Please see documentation at: http://pillow.readthedocs.io/en/latest/installation.html#external-libraries

I downloaded the T-LESS dataset from the BOP, which lacks images 08-109.png, 08-110.png, 09-244.png, 14-367.png, 18-497.png. I downloaded the corresponding file from the official website, and it is still error in the position of 09-244.png after being placed.

Can you tell me how to solve it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
lh641446825commented, Nov 21, 2019

Hello, I solved this problem, add the following code:

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
0reactions
lh641446825commented, Nov 19, 2019

Thank you very much for your help. Although I still haven’t solved the problem after using the pictures you provided. When I try to load images with other image libraries, the error is:

Recognizing scene_id:9, im_id:242
Recognizing scene_id:9, im_id:243
libpng error: Read Error
Traceback (most recent call last):
  File "/home/Pix2Pose/tools/5_evaluation_bop_basic.py", line 261, in <module>
    image_t = cv2.imread(rgb_path)[:, :, ::-1]
TypeError: 'NoneType' object is not subscriptable

I am very sorry to trouble you for so long. I will find the reason myself. Best wish.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PIL "IOError: image file truncated" with big images
Feroze is right - it is caused by trimming data on some point in data flow chain. One frequent cause is not flushing...
Read more >
OSError: image file is truncated (38 bytes not processed)
I'm getting following error in midway of second epoch. First epoch ran successfully without any error. ... What could be the reason? I...
Read more >
python-pillow/Pillow - Gitter
How can a OSError: image file is truncated (0 bytes not processed) error occur? It occurs when I load an image (successfully and...
Read more >
"OSError: image file is truncated" when uploading - CodaLab -
Hi hellosr,. I looked into your submitted files. In your failed submission, the file 20_00000089.png is not complete and cannot be opened by...
Read more >
Source code for PIL.ImageFile - Pillow - Read the Docs
_util import is_path MAXBLOCK = 65536 SAFEBLOCK = 1024 * 1024 LOAD_TRUNCATED_IMAGES = False """Whether or not to load truncated image files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found