M2Det으로 물체 검출해 보았다!
11930 단어 GoogleColaboratory파이썬M2Det물체 감지
할 일
전회과 지난번에서 SSD와 YOLO v3에서 각각 물체 검출을 실시해 보았습니다. 이번에는 M2Det에서 물체 검출을 실시해 보겠습니다.
개요
실행 환경
1. 실행 환경 준비 (Google Colaboratory에서 실행)

그런 다음 다음을 수행합니다.
실행 환경 준비
!pip install torch torchvision
!pip install opencv-python tqdm addict
!git clone https://github.com/qijiezhao/M2Det.git
%cd M2Det/
!sh make.sh
2. Google Drive에서 모델 다운로드
GitHub의 README에 학습 된 모델 링크가 포함되어 있습니다 (h tps://d ゔぇ. 오, ぇ. 코 m / 후 / d / 1 m M1 ud d Z w w 2 Dhhc P - Wj 24m - 90L / ぃ w).
download_file_from_google_drive
를 실행하면 명령으로 다운로드 할 수 있습니다 import requests
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
if token:
params = { 'id' : id, 'confirm' : token }
response = session.get(URL, params = params, stream = True)
save_response_content(response, destination)
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, destination):
CHUNK_SIZE = 32768
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
file_id = '1NM1UDdZnwHwiNDxhcP-nndaWj24m-90L'
destination = './m2det512_vgg.pth'
download_file_from_google_drive(file_id, destination)
3. 이미지 파일 복사
GoogleDrive 마운트
from google.colab import drive
drive.mount('/content/drive')
이미지 파일 복사
!cp /content/drive/My\ Drive/ML/work/*.jpg ./imgs
4. 모델 실행
모델 실행
!python demo.py -c=configs/m2det512_vgg.py -m=m2det512_vgg.pth
5. 결과 표시
import cv2
import matplotlib.pyplot as plt
plt.figure(figsize=(5, 5), dpi=200)
img = cv2.imread('imgs/herd_of_horses_m2det.jpg')
show_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(show_img)




소스 코드
참고
Reference
이 문제에 관하여(M2Det으로 물체 검출해 보았다!), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hiraku00/items/972ec178a6892ef77e63텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)