0

I wanted to load and plot images with masks on detectron2. But during loading, it throws me such error:

      6     for s in random.sample(dataset_custom, n):
      7         img = cv2.imread(s['file_name'])
----> 8         v = Visualizer(img[:,:,::-1], metadata = dataset_custom_metadata, scale = 0.5)
      9         v  = v.draw_dataset_dict(s)
     10         #plt.figure(figsize = (15, 20))

TypeError: 'NoneType' object is not subscriptable
add Codeadd Markdown

Also, I got such error in colab and kaggle notebooks. In my local jupyter, I did not get this error. What to do to get rid of TypeError? Can I leave this step and do not use Visualizer or is it needed during segmentation?

2 Answers2

0

use->

cv2_imshow(v.get_image()[:, :, ::-1])

instead of

plt.show()

Another solution can be:

 plt.imshow(v.get_image()[:, :, ::-1])
 plt.show()
0

You should check that you are in the correct directory with the images you try to visualize. I've got the same problem

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 19 '22 at 08:56