환경
Ubuntu 16.04
GeForce RTX 2080
1. 학습 준비하기
1.1 COCO 데이터 세트를 이용한 학습
COCO 데이터는 2014 , 2017 로 나뉘어져 있는데, 홈페이지에서 다운 받을 수도 있지만,
크기가 너무 커서 유틸리티 curl 를 이용하여 다운받아야 한다.
COCO 데이터 세트 https://cocodataset.org/#download
COCO - Common Objects in Context
cocodataset.org
COCO 데이터 세트 종류는 다음과 같다.
- 이미지
- 2014 Train images [83K/13GB]
- 2014 Val images [41K/6GB]
- 2014 Test images [41K/6GB]
- 2015 Test images [81K/12GB]
- 2017 Train images [118K/18GB]
- 2017 Val images [5K/1GB]
- 2017 Test images [41K/6GB]
- 2017 Unlabeled images [123K/19GB]
- 주석
- 2014 Train/Val annotations [241MB]
- 2014 Testing Image info [1MB]
- 2015 Testing Image info [2MB]
- 2017 Train/Val annotations [241MB]
- 2017 Stuff Train/Val annotations [1.1GB]
- 2017 Panoptic Train/Val annotations [821MB]
- 2017 Testing Image info [1MB]
- 2017 Unlabeled Image info [4MB]
curl 다운로드
$ sudo apt install curl
$ curl https://sdk.cloud.google.com | bash
$ source ~/.bashrc
COCO 데이터 세트 다운로드
$ mkdir COCO
$ cd COCO
$ mkdir val2017
$ gsutil -m rsync gs://images.cocodataset.org/val2017 val2017
$ mkdir annotation
$ gsutil -m rsync gs://images.cocodataset.org/annotations annotation
$ cd val2017
$ unzip ../anns/annotations_trainval2017.zip
다른 데이터는 다음과 같이 받으면 된다.
$ gsutil -m rsync gs://images.cocodataset.org/train2017 train2017
val2017 이미지 데이터는 5,000장으로 이루어져있으며, annotation은 다음과 같이 구성되어 있다.
- caption : 영상에 대한 설명
- person_keypoints : 사람의 관절 좌표 데이터
- instances : 영상에 포함된 사람 혹은 사물에 대한 카테고리와 Segmentation 정보
COCO 데이터 세트는 COCO API 를 이용하여 다룰 수 있다.
COCO API : https://github.com/cocodataset/cocoapi
cocodataset/cocoapi
COCO API - Dataset @ http://cocodataset.org/ . Contribute to cocodataset/cocoapi development by creating an account on GitHub.
github.com
COCO 데이터 주석 확인은 아래와 같이 json viewer 를 통해 볼 수 있다.
JSON Viewer : http://jsonviewer.stack.hu/
jq 라는 유틸리티를 통해 줄바꿈하여 편하게 볼 수 있다. 보는 방법은 아래 포스팅 참고
https://eehoeskrap.tistory.com/336
[JSON] JSON 파일 뷰어
http://jsonviewer.stack.hu/ Online JSON Viewer jsonviewer.stack.hu 이 페이지에 마우스로 json 파일을 잡아다 끌면 내용이 보인다. 그리고 참고로 jq 라는 것을 이용하여 json 의 내용을 다음과 같이 줄바꿈..
eehoeskrap.tistory.com
COCO 데이터 주석은 아래와 같다. (instances_val2017.json 파일 확인함)
{
"info": {
"description": "COCO 2017 Dataset",
"url": "http://cocodataset.org",
"version": "1.0",
"year": 2017,
"contributor": "COCO Consortium",
"date_created": "2017/09/01"
},
"licenses": [
{
"url": "http://creativecommons.org/licenses/by-nc-sa/2.0/",
"id": 1,
"name": "Attribution-NonCommercial-ShareAlike License"
},
{
"url": "http://creativecommons.org/licenses/by-nc/2.0/",
"id": 2,
"name": "Attribution-NonCommercial License"
},
...
],
"images": [
{
"license": 4,
"file_name": "000000397133.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000397133.jpg",
"height": 427,
"width": 640,
"date_captured": "2013-11-14 17:02:52",
"flickr_url": "http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg",
"id": 397133
},
{
"license": 1,
"file_name": "000000037777.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000037777.jpg",
"height": 230,
"width": 352,
"date_captured": "2013-11-14 20:55:31",
"flickr_url": "http://farm9.staticflickr.com/8429/7839199426_f6d48aa585_z.jpg",
"id": 37777
},
{
"license": 4,
"file_name": "000000252219.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000252219.jpg",
"height": 428,
"width": 640,
"date_captured": "2013-11-14 22:32:02",
"flickr_url": "http://farm4.staticflickr.com/3446/3232237447_13d84bd0a1_z.jpg",
"id": 252219
},
...
{
"segmentation": [
[
83.22,
632.06,
1.51,
627.52,
1.51,
509.5,
0,
453.52,
102.88,
389.98,
140.71,
370.31,
164.92,
344.59,
178.53,
344.59,
190.64,
379.39,
204.26,
373.33,
208.79,
365.77,
223.92,
373.33,
240.57,
365.77,
211.82,
324.92,
217.87,
303.74,
264.78,
279.53,
338.91,
294.66,
369.17,
294.66,
437.26,
305.25,
447.85,
317.35,
447.85,
337.02,
480,
352.15,
478.11,
632.06,
266.29,
629.03,
51.44,
627.52
]
],
"area": 136955.75629999995,
"iscrowd": 0,
"image_id": 17899,
"bbox": [
0,
279.53,
480,
352.53
],
"category_id": 67,
"id": 119334
},
...
1.2 데이터 포맷을 Yolo 형식으로 바꾸기
1.1에서와 같이 COCO 데이터 포맷은 bbox 값이 x, y, w, h 값으로 구성되어있다.
하지만 yolo 에서의 포맷은 클래스 번호와 전체 영상 크기에 대한 center x, center y, w, h 비율 값으로 구성된다.
또한 COCO 는 모든 영상의 주석이 담겨진 하나의 json 파일로 구성되어있으며,
Yolo 는 한 영상 당 한 개의 txt 파일로 구성되어있다. (예를 들면 5000개의 영상, 5000개의 주석)
예를 들면 사람 클래스(0번)에 대한 주석은 다음과 같다.
COCO Format : 0 279.53 480, 352.53
Yolo Format : 0 0.256 0.315 0.506 0.593
그래서 기존 COCO 데이터 세트의 포맷을 YOLO 포맷으로 변환시켜야 한다.
관련 포스팅은 아래와 같다.
https://eehoeskrap.tistory.com/351
[Object Detection] 객체 탐지를 위한 데이터 주석 Yolo 형식으로 변환하기
https://github.com/ssaru/convert2Yolo ssaru/convert2Yolo This project purpose is convert voc annotation xml file to yolo-darknet training file format - ssaru/convert2Yolo github.com 위 깃허브 저장소..
eehoeskrap.tistory.com
1.3 Own Dataset 을 이용한 학습
1.3.1 영상 데이터 수집하기
원하는 영상 데이터를 수집한다.
자신이 데이터 크롤링을 통해 모을 수도 있고(라벨링 필요함), 오픈된 이미지 세트를 이용해도 된다.
Object Detection 에서 많이 사용하는 데이터는 COCO 이외에 아래와 같은 것들이 있다.
- COCO
- Open Image
- VOC
- UDACITY Object Detection
- KITTI 2D Object Detection
단, YOLO 포맷으로 변환하는 과정이 필요하다. 또한 자신이 데이터 크롤링을 통해 모을 경우 라벨링 작업이 필요하다.
1.3.2 Annotation Tool을 이용한 데이터 라벨링
데이터 라벨링은 유명한 labelimg 라는 툴을 이용 할 수 있다. 바로 Yolo 형식으로 저장이 가능하다.
아래 포스팅 참고
https://eehoeskrap.tistory.com/331
[Object Detection] Image Labeling Tool
유명한 이미지 라벨링 툴 labelImg 이다. object detection 학습을 위해 영상에서 Bounding Box 를 지정하여 라벨링을 수행하고 그 bounding box 정보들을 .xml 로 저장 할 수 있다. https://github.com/tzutalin/..
eehoeskrap.tistory.com
1.4 class.names 파일 생성하기
클래스 이름이 담긴 파일을 생성한다.
Person 만 Detection 하고 싶은 경우 파일 내용은 아래와 같다. (person.names)
person
COCO 의 모든 클래스 (80)개에 대해서만 검출하고 싶은 경우 파일 내용은 아래와 같다. (coco80.names)
person
bicycle
car
motorcycle
airoplane
bus
train
truck
boat
traffic light
fire hydrant
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
backpack
umbrella
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
sofa
potted plant
bed
dining table
toilet
tv
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
book
clock
vase
scissors
teddy bear
hair drier
toothbrush
1.5 Darknet 다운로드 하기
이제 데이터에 대한 준비가 끝났으면 아래와 같이 Darknet 을 다운로드 한다.
$ git clone https://github.com/pjreddie/darknet.git
Darknet 학습하기는 다음 포스팅을 참고하길
eehoeskrap.tistory.com/370?category=705416
[Object Detection] darknet custom 학습하기
darknet 학습을 위해 이전에 처리해야할 과정들은 다음 포스팅을 참고 [Object Detection] darknet custom 학습 준비하기 https://eehoeskrap.tistory.com/367 [Object Detection] Darknet 학습 준비하기 환경 Ubu..
eehoeskrap.tistory.com
참고자료 1
https://ukayzm.github.io/cocodataset/
COCO Dataset
머신러닝을 위해 많은 데이터 셋이 만들어져 있는데, 그 중에 COCO dataset은 object detection, segmentation, keypoint detection 등을 위한 데이터셋으로, 매년 다른 데이터셋으로 전 세계의 여러 대학/기업이 참가하는 대회에 사용되고 있습니다. 구글이 공개한 TensorFlow Object Detection API에도 COCO dataset으로 학습시킨 모델이 들어있습니다. 이 COCO dataset과 이것을
ukayzm.github.io
'AI Research Topic > Object Detection' 카테고리의 다른 글
[Object Detection] darknet custom 학습하기 (83) | 2019.10.16 |
---|---|
[Object Detection] COCO Category 91 vs 80 (3) | 2019.10.08 |
[Object Detection] YOLO style 로 Bounding Box 값 바꾸기 (12) | 2019.09.17 |
[Object Detection] Darknet python (2) | 2019.09.04 |
[Object Detection] Darknet 학습 시 적절한 Weight 고르기 (0) | 2019.09.04 |