解决报错:struct.error: unpack_from requires a buffer of at least 4 bytes

发布于:2021-10-14 08:48:47

好久没更了(大概是因为在国外抗疫hhh),言归正传。


最*实验到后期,跑今年的SOTA提取语义mask的时候,批量处理图片时出现报错。


Traceback (most recent call last):
File "/home/xiaoman/.local/lib/python3.6/site-packages/PIL/ImageFile.py", line 235, in load
s = read(self.decodermaxblock)
File "/home/xiaoman/.local/lib/python3.6/site-packages/PIL/PngImagePlugin.py", line 659, in load_read
cid, pos, length = self.png.read()
File "/home/xiaoman/.local/lib/python3.6/site-packages/PIL/PngImagePlugin.py", line 122, in read
length = i32(s)
File "/home/xiaoman/.local/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

搜了一下,出现该报错在不同应用下解决答案不同,但是根本原因是函数unpack_from在使用的时候,输入的参数不对,解决问题的关键就是查看数据源和参数设定。该函数有三个参量:fmt,buffer,offfset,一般buffer不会出问题。然后我就去check了一下测试的图片集,结果发现了问题:



该图片大小不对,删掉,bug解决。

相关推荐

最新更新

猜你喜欢