Open
Description
🐛 Describe the bug
I have encountered an issue where using torchvision.io.read_image
(as well as decode_image
and decode_gif
) on certain GIF files produces an invalid output. Here is a code:
import cv2
from torchvision.io import read_image
gif = read_image('sample.gif').numpy().transpose(0, 2, 3, 1)
image = gif[15] # 15-th frame
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
cv2.imshow('read_torch', image)
cv2.waitKey()
Sample of buggy GIF:
Its source: https://i.pinimg.com/originals/a0/02/a3/a002a3e51a2adc85d6c0a4684892e743.gif
I understand that this may be an underlying issue of GIFLIB and will not be fixed. However, since the behavior is unexpected and could impact users, it might be beneficial to include a note in the docs.
Versions
I found this behavior on Macbook and Linux server. They have different setup, but both of them use the latest versions:
torch==2.6.0
torchvision==0.21.0