facebookresearch / maskrcnn-benchmark

Fast, modular reference implementation of Instance Segmentation and Object Detection algorithms in PyTorch.
MIT License
9.31k stars 2.49k forks source link

Image type of COCODataset class #1311

Closed leop123 closed 3 years ago

leop123 commented 3 years ago

❓ Questions and Help

So I'm trying to visualize my test result following this instruction, I cannot output the image since the image type is different. For image, target, idx = dataset[idx] I got an image with data type torch.Tensor from dataset maskrcnn_benchmark.data.datasets.coco.COCODataset with shape (3, 600, 1200).

The original image from dataset.get_img_info(idx) is {'id': 0, 'width': 2048, 'height': 1024, 'file_name': 'frankfurt_000000_000294_leftImg8bit_foggy_beta_0.02.png', 'seg_file_name': 'frankfurt_000000_000294_gtFine_instanceIds.png'}

The problem is the torch.Tensor image value is vary between around -122.7717 to 152.0199. I wonder how to convert this to ordinary image type so I can overlay the predictions on top of the image and visualize the test result. Also do I need to reshape the image to original size 1024 x 2048 before I overlay the prediction on top of the image?

Thanks.

leop123 commented 3 years ago

It turns out that the values are normalized with different mean each color. See https://github.com/facebookresearch/maskrcnn-benchmark/blob/57eec25b75144d9fb1a6857f32553e1574177daf/maskrcnn_benchmark/config/defaults.py#L51 I change the image to numpy and denormalized it and transpose before I overlay the prediction box and text.