MMDetection-inference by mim

Published by onesixx on

MMDection 설치후 Inference수행

https://github.com/sixxchung/mmdetection/blob/master/docs/en/get_started.md

  • 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.

Options:
  --user-conf FILE  Read option defaults from the .mimrc file  [default:
                    /home/oschung_skcc/.mimrc]

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

Commands:
  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      https://github.com/open-mmlab/mmcv
mmdet      2.21.0     https://github.com/open-mmlab/mmdetection

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 다운로드
  • faster_rcnn_r50_fpn_1x_coco.py 다운로드 (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/faster_rcnn_r50_fpn_1x_coco.py'

# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
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

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x