ImageAI 를 활용한 15줄짜리 object detection
더욱 자세한 정보는
https://towardsdatascience.com/object-detection-with-10-lines-of-code-d6cb4d86f606
Object Detection with 10 lines of code
Part 2 of this tutorial for detecting your custom objects is available via this link.
towardsdatascience.com
여기 글을 참고해서 포스팅합니다.
문제가 생길시, 지우도록하겠습니다.
faster rcnn, yolo 등 다양한 오브젝트 디텍션 모델들이 나와있지만, 초보자가 사용하기가 힘든 문제점이 있다.
그래서 이번에는 아주 간단하지만 괜찮은 성능을 보여주는 간단한 코딩을 해볼 예정이다.
사전에 앞서,
실습환경: jupyter lab
version : python3.7, keras, tensorflow, matplot, imageai 모듈이 깔려있다고 가정한다.
ImageAI는 pip install imageai 명령어를 통해 간편하게 설치할 수 있다.
또한 실습에 필요한 pre-trained 된 모델은 retinanet을 이용하였으며, link< 여기서 받을 수 있다.


위 그림처럼 결과를 얻을 수 있으며, 아마 coco dataset기반으로 pretrained 된 모델이니 디텍션 결과 종류를 얻을 수 있을 것이다.
그리고 조금만 수정한다면 실시간으로 처리하고 하는 부분도 가능할꺼같다.
전체소스 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import numpy as np import matplotlib.pyplot as plt from matplotlib.image import imread from imageai.Detection import ObjectDetection import os detector = ObjectDetection() detector.setModelTypeAsRetinaNet() detector.setModelPath("model/resnet50_coco_best_v2.0.1.h5") detector.loadModel() detections = detector.detectObjectsFromImage(input_image="input_images/image.jpg", output_image_path="output_images/image.jpg") for eachObject in detections: print(eachObject["name"] , " : " , eachObject["percentage_probability"] ) img = imread('output_images/image.jpg') plt.imshow(img) |
cs |
만약 coco dataset 처럼 custom 데이터와 위치정보 라벨된 데이터셋이 있어서 학습을 시키고 싶다면,
아래 코드로 간편하게 학습도 가능한거 같다.
결국 데이터가 ..ㅠ
https://medium.com/deepquestai/train-object-detection-ai-with-6-lines-of-code-6d087063f6ff
Train Object Detection AI with 6 lines of code
Step-by-step tutorial on training object detection models on your own dataset
medium.com