open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.02k stars 9.36k forks source link

[for help] RTMDetIns visualization isu #9934

Open Wooho-Moon opened 1 year ago

Wooho-Moon commented 1 year ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

master branch https://github.com/open-mmlab/mmdetection

Environment

sys.platform: linux Python: 3.7.16 (default, Jan 17 2023, 22:20:44) [GCC 11.2.0] CUDA available: True numpy_random_seed: 2147483648 GPU 0,1,2,3: NVIDIA GeForce RTX 3090 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.3, V11.3.109 GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.11.0 PyTorch compiling details: PyTorch built with:

TorchVision: 0.12.0 OpenCV: 4.7.0 MMEngine: 0.6.0 MMDetection: 3.0.0rc6+61dd8d5

Reproduces the problem - code sample

import torch, torchvision import mmdet import mmcv import mmengine

import mmcv import mmengine

from mmdet.apis import init_detector, inference_detector from mmdet.utils import register_all_modules

Choose to use a config and initialize the detector

config_file = '/home/workspace/segmantation/instance/mmdetection/configs/rtmdet/rtmdet-ins_x_8xb16-300e_coco.py'

Setup a checkpoint file to load

checkpoint_file = '/home/workspace/segmantation/instance/mmdeploy/checkpoint/rtmdet-ins_x_8xb16-300e_coco_20221124_111313-33d4595b.pth'

register all modules in mmdet into the registries

register_all_modules()

build the model from a config file and a checkpoint file

model = init_detector(config_file, checkpoint_file, device='cuda:0') # or device='cuda:0'

Use the detector to do inference

image = mmcv.imread('/home/workspace/segmantation/instance/mmdetection/demo/demo.jpg',channel_order='rgb') result = inference_detector(model, image) print(result)

from mmdet.registry import VISUALIZERS

init visualizer(run the block only once in jupyter notebook)

visualizer = VISUALIZERS.build(model.cfg.visualizer)

the dataset_meta is loaded from the checkpoint and

then pass to the model in init_detector

visualizer.dataset_meta = model.dataset_meta

show the results

visualizer.add_datasample( 'result', image, data_sample=result, draw_gt = None, wait_time=0, out_file=None, pred_score_thr=0.4 )

visualizer.show()

Reproduces the problem - command or script

it is not a command. it is run on jupyternotebook.(ipynb)

Reproduces the problem - error message

there is no error but the result is so wired.

the result is here

image

what should i do? how can I solve this problem?

Additional information

No response

Wooho-Moon commented 1 year ago

ah I use a model which is pretrained on this repository. the model is RTMDetIns-x, and I use a config file named rtmdet-ins_x_8xb16-300e_coco.py

RangiLyu commented 1 year ago

I copy your code and run it, but the result is correct.

import torch, torchvision
import mmdet
import mmcv
import mmengine

import mmcv
import mmengine

from mmdet.apis import init_detector, inference_detector
from mmdet.utils import register_all_modules

config_file = 'configs/rtmdet/rtmdet-ins_x_8xb16-300e_coco.py'
checkpoint_file = '~/models/rtmins/gather_model/rtmdet/rtmdet-ins_x_8xb16-300e_coco/rtmdet-ins_x_8xb16-300e_coco_20221124_111313-33d4595b.pth'
register_all_modules()
model = init_detector(config_file, checkpoint_file, device='cuda:0')  # or device='cuda:0'

image = mmcv.imread('demo/demo.jpg', channel_order='rgb')
result = inference_detector(model, image)
print(result)
from mmdet.registry import VISUALIZERS

visualizer = VISUALIZERS.build(model.cfg.visualizer)

visualizer.dataset_meta = model.dataset_meta
visualizer.add_datasample(
    'result',
    image,
    data_sample=result,
    draw_gt=None,
    wait_time=0,
    out_file=None,
    pred_score_thr=0.4
)

visualizer.show()

image

Wooho-Moon commented 1 year ago

umm.. ok.. I will try again. thanks alot:)

ZhuYihan-UMI commented 1 year ago

Hi Wooho-Moon, I met similar issue with you, and also carefully examine the codes, environments, changed a few computers to try, but could not solve the problem, and I searched all over the internet but finds no answers.

If you are also carefully examine the codes line by line, just like what I did, but still see errors, you may want to try the following solution.

Eventually the solutions turns out surprisingly simple: Just run all the scripts together. like what [RangiLyu] did. Use "run all" from the get-go.

Hope this helps.