MMDetection-inference by mim

Published onesixx on

MMDection 설치후 Inference수행

  • Prerequisites 파일 설치
  • 새로운 conda 환경 설치 (vscode : default 환경설정)
  • clone mm
  • mim을 사용하여 mmdetection 설치
$ mim

Usage: mim [OPTIONS] COMMAND [ARGS]...

  OpenMMLab Command Line Interface.

  MIM provides a unified API for launching and installing OpenMMLab projects
  and their extensions, and managing the OpenMMLab model zoo.

  --user-conf FILE  Read option defaults from the .mimrc file  [default:

  --version         Show the version and exit.
  -h, --help        Show this message and exit.

  download    Download checkpoints from url and parse configs from package.

  run         Run arbitrary command of a codebase.
  test        Perform Testing.
  train       Perform Training.
  search      Show the information of packages.
  gridsearch  Perform Hyper-parameter search.
  list        List packages.  
  install     Install package.
  uninstall   Uninstall package.
$ mim list
Package    Version    Source
---------  ---------  -----------------------------------------
mmcv-full  1.4.4
mmdet      2.21.0

Inference 수행 (Pretrained 모델을 활용)

mim은 위와 같이 mim install mmdet 으로 설치도 할수 있지만,
mim 의 download 명령을 사용하면,
특정 Config와 해당 Checkpoint를 다운로드 받을 수 있다.

$ mim download mmdet \\
      --config faster_rcnn_r50_fpn_1x_coco \\
      --dest   .
  • faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth 다운로드
  • 다운로드 (config)


  • init_detector : config파일과 checkpoint 파일을 이용해 detector를 생성
  • inference_detection : 만든 detector를 가지고, inference해 본다.
  • show_result_pyplot: 시각화해서 보여준다.
from mmdet.apis import init_detector, inference_detector, show_result_pyplot

config_file = 'configs/faster_rcnn/'

# download the checkpoint from model zoo and put it in `checkpoints/`
# url:
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'

# init a detector
device = 'cuda:0'
model = init_detector(config_file, checkpoint_file, device=device)
# model.__dict__
# print(model.cfg.pretty_text)

# inference the demo image
img = 'demo/demo.jpg'
# img_arr = cv2.imread(img)
# img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB)

inference_detector(model, img)

show_result_pyplot(model, img, results)   # (class confidence) score threadhold 0.3

list순서에 따른 class 명

Categories: vision


Blog Owner

Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x