解決報錯:struct.error: unpack_from requires a buffer of at least 4 bytes

好久沒更了(大概是因爲在國外抗疫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解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章