Python - Object Detection 실습

roboflow

  • 컴퓨터 비전 모델 개발 관련 서비스를 제공하는 종합 플랫폼.
    • 이미지 데이터셋
    • 데이터 증강
    • 모델 학습/배포/버전관리
    • 협업

  • 회원가입을 완료한 후 Mask Wearing Dataset을 클릭한다.
    (Public Datasets는 무료로 사용 가능한 dataset이다.)

  • Downloads에서 416x416-black-padding을 클릭한다.

  • YOLO Darknet을 클릭하여 show download code를 선택하고 continue를 클릭한다.

  • continue를 실행하여 "direct link to download yout zip file is:" 메시지와 함께 링크가 주어진다. 해당 링크를 복사한다. (링크에는 개인 정보가 포함되어 있기 때문에 유출되지 않도록 한다.)

수동 라벨링 매기기

Projects


 > New Project

- Project Name: 프로젝트명
- Annotaion Group: 레이블명(클래스)

> Upload Data > Save and Continue


라벨링(클래스)

Manual Labeling > Assign to Myself

Annotate > Start Annotating (완료되면 <-)
> Add 2 images to Dataset

Classes &tag


전처리 및 증강

Versions >
Preprocessing (전처리)
Augmentaton (증강)
> Download Dataset
(쥬피터 형태로 받으면, 코랩에서 바로 다운로드 받을 수 있음)



데이터셋 다운로드

!curl -L "https://public.roboflow.com/ds/febQsKq5La?key=1aOGF8OpT3" > roboflow.zip; unzip roboflow.zip; rm roboflow.zip
  • curl: web에 요청을 하는 명령어이다.
  • -L: 서버링크가 다른 주소로 re-direct되어 있을 경우 re-direct 주소까지 접속하는 curl 옵션이다.

Python 코드

import os
import glob
import pandas as pd

import xml.etree.ElementTree as ET

!pip install --upgrade gdown

!gdown 1243y4NFGU9rZkiD_VGivE2HInP-u5dUcㅡ

!unzip mask_xml.zip

경로 확인

data.yaml 파일

  • train: ./train/images
  • val: ./valid/images
  • nc: 2    # num_class 갯수 (출력값 갯수)
  • names: ['mask', 'no-mask']    # 출력값 레이블


getroot(): 마크업으로 가져오기

tree = ET.parse('/content/-1x-1_jpg.rf.6b3d2c5412e0027ef0b2c5cd157dfda3.xml')
root = tree.getroot()
root


root.findall(' ') 

  • 지정한 정보를 모두 리스트로 가져온다.

  • root.findall('object')

root.findall('object')[0].find('bndbox').find('xmin').text

  • find : 지정한 element 하나를 가져온다.

  • .text : element의 contents 를 가져온다.


annotation 정보를 Yolo format으로 변환

xml(pascal형식) -> json(yolo형식)


증강으로 인한 데이터셋 변경

augmentation_with_albumentation

위치정보(b-box정보)가 있는 이미지를 crop하면, 어떡해야 할까?

  • 잘리진 않은 경우: x, y만 수정

  • 일부가 잘리는 경우: x, y와 width, height 수정
    • 최소한의 b-box 영역이 남아있는가?
      • 절대값 사이즈
      • 비율

  • 통으로 잘리는 경우: 위치정보 제거

튜토리얼

https://albumentations.ai/docs/getting_started/bounding_boxes_augmentation/




댓글 쓰기

다음 이전