๐ MMDeteection ๊ฐ์
- ์นญํ ๋ํ์ ์ฃผ๋๋ก ๋ง๋ค์ด์ง C.V Open Source Project์ธ OpenMMLab์์ ์์
- ๋ค์ํ Object Detection, Segmentation ์๊ณ ๋ฆฌ์ฆ์ Package๋ก ๊ตฌํ ์ ๊ณต
- ๊ตฌํ ์ฑ๋ฅ, ํจ์จ์ ์ธ ๋ชจ๋ ์ค๊ณ, Config ๊ธฐ๋ฐ์ผ๋ก ํ์ต / ํ๊ฐ ๊น์ง ์คํ๋๋ ํ์ดํ๋ผ์ธ ์ ์ฉ
- Pytorch ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํ
๐ MMDeteection ๊ตฌํ
# config ํ์ผ์ ์ค์ ํ๊ณ , ๋ค์ด๋ก๋ ๋ฐ์ pretrained ๋ชจ๋ธ์ checkpoint๋ก ์ค์ .
config_file = '/content/mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = '/content/mmdetection/checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# config ํ์ผ๊ณผ pretrained ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก Detector ๋ชจ๋ธ์ ์์ฑ.
from mmdet.apis import init_detector, inference_detector
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# mmdetection์ ์๋ ๊ฒฝ๋ก๋ฅผ ์ธ์๋ก ์ฃผ๋ฉด ๋ฌด์กฐ๊ฑด mmdetection ๋๋ ํ ๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก ํจ.
%cd mmdetection
from mmdet.apis import init_detector, inference_detector
# init_detector() ์ธ์๋ก config์ checkpoint๋ฅผ ์
๋ ฅํจ.
model = init_detector(config='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', checkpoint='checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth')
import cv2
import matplotlib.pyplot as plt
img = '/content/mmdetection/demo/demo.jpg'
img_arr = cv2.cvtColor(cv2.imread(img), cv2.COLOR_BGR2RGB)
plt.figure(figsize=(12, 12))
plt.imshow(img_arr)
img = '/content/mmdetection/demo/demo.jpg'
# inference_detector์ ์ธ์๋ก string(file๊ฒฝ๋ก), ndarray๊ฐ ๋จ์ผ ๋๋ listํํ๋ก ์
๋ ฅ ๋ ์ ์์.
results = inference_detector(model, img)
from mmdet.apis import show_result_pyplot
# inference ๋ ๊ฒฐ๊ณผ๋ฅผ ์๋ณธ ์ด๋ฏธ์ง์ ์ ์ฉํ์ฌ ์๋ก์ด image๋ก ์์ฑ(bbox ์ฒ๋ฆฌ๋ image)
# Default๋ก score threshold๊ฐ 0.3 ์ด์์ธ Object๋ค๋ง ์๊ฐํ ์ ์ฉ. show_result_pyplot์ model.show_result()๋ฅผ ํธ์ถ.
show_result_pyplot(model, img, results)
๐ DataSet / COCO Data Set / 80๊ฐ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํ
๐ Opencv ๊ธฐ๋ฐ ๊ตฌํ
import cv2
# RGB๊ฐ ์๋ BGR๋ก ์
๋ ฅ
img_arr = cv2.imread('/content/mmdetection/demo/demo.jpg')
results = inference_detector(model, img_arr)
show_result_pyplot(model, img_arr, results)
→ array๋ฅผ inference_detector()์ ์ ๋ ฅํ ๊ฒฝ์ฐ, ์๋ณธ array๋ฅผ BGR ํํ๋ก ์ ๋ ฅ ํ์
(RGB ๋ณํ์ ๋ด๋ถ์์ ์ํํ๋ฏ๋ก, BGR๋ก ์ ๋ ฅ ํ์, RGB ๋ณํ ์, ๋ฐ๋๋ก ์ถ๋ ฅ๋จ)
'MLDL_์ ๋ฆฌ > Sample' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DL] OpenAOI Git (0) | 2022.05.09 |
---|---|
[DL] CIFAR-10 (0) | 2022.03.22 |
[DL] - MediaPipe / Video pose Detection (0) | 2022.03.06 |
[DL] - MediaPipe / Video Object Detection (0) | 2022.03.06 |
[DL] - ์ ํ๋ ์ธก์ (0) | 2022.03.01 |