Pytorch and Matplotlib interfering

  Kiến thức lập trình

I’m facing a weird bug with Matplotlib and torch. If I run with this torch.hub.load line the plt.imshow will simply not display anything (even tho frame is a correct image). If I comment this line the plt.imshow works.

Whether this torch.hub.load line is commented or not cv2.imshow will work.

onnx_path = "my_weights.onnx"
yolo_path = "lib/yolov5/"


torch.hub.load(yolo_path, 'custom', path=onnx_path, source='local') 

video_reader = VideoReader(str(src_file))

# wait for thread to read
while not video_reader.is_ready():
    waiting += 1
    time.sleep(1)

while(video_reader.is_ready()):
   frame = video_reader.frame

   #cv2.imshow('image',frame)
   #cv2.waitKey(0)


   plt.imshow(frame)
   plt.axis('off')
   plt.show()

It seems i’m missing something but I don’t see it. Any help is appreciated 🙂

LEAVE A COMMENT