[Computer Vision] COCO 데이터셋

2023. 11. 24. 10:36ML&DL/CV

COCO Dataset

https://cocodataset.org/#home

 

COCO - Common Objects in Context

 

cocodataset.org

  • COCO 데이터셋은 객체 인식과 분할을 위한 대규모 데이터셋 중 하나로 널리 사용되고 있는 데이터셋 중 하나다.
  • 약 33만 개의 이미지, 약 80개의 객체 클래스 , 91개의 stuff 클래스 (객체가 아닌 배경같은 것)

 

 

Dataset download

- train / val/ test 이미지, annotation 파일

Dataset 객체 클래스 

- 2017 버전

- 90개의 클래스

  • person, bicycle, car, motorcycle, airplane, 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, couch, 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

Dataset 이미지 살펴보기

- annotation 되어있는 객체 

 

 

 

 

 Annotation.json 파일

- 이미지에 대한 정보가 들어있는 파일

ex)

{
	"info": {
		"year": 2021,
		"version": "1.0",
		"description": "For object detection",
		"date_created": "2021"
	},
	"images": [
		{
			"date_captured": "2021",
			"file_name": "000000000001.jpg",
			"id": 1,
			"height": 480,
			"width": 640
		},
		{
			"date_captured": "2021",
			"file_name": "000000000002.jpg",
			"id": 2,
			"height": 426,
			"width": 640
		},
		{
			"date_captured": "2021",
			"file_name": "000000000003.jpg",
			"id": 3,
			"height": 428,
			"width": 640
		},
		{
			"date_captured": "2021",
			"file_name": "000000000004.jpg",
			"id": 4,
			"height": 425,
			"width": 640
		},
		{
			"date_captured": "2021",
			"file_name": "000000000005.jpg",
			"id": 5,
			"height": 640,
			"width": 481
		}
	],
	"licenses": [
		{
			"id": 1,
			"name": "GNU General Public License v3.0",
			"url": "https://github.com/zhiqwang/yolov5-rt-stack/blob/master/LICENSE"
		}
	],
	"type": "instances",
	"annotations": [
		{
			"segmentation": [
				[
					1.0799999999999272,
					187.69008000000002,
					612.66976,
					187.69008000000002,
					612.66976,
					473.53008000000005,
					1.0799999999999272,
					473.53008000000005
				]
			],
			"area": 174816.81699840003,
			"iscrowd": 0,
			"image_id": 1,
			"bbox": [
				1.0799999999999272,
				187.69008000000002,
				611.5897600000001,
				285.84000000000003
			],
			"category_id": 19,
			"id": 1
		},
		{
			"segmentation": [
				[
					311.73024,
					4.310159999999996,
					631.0102400000001,
					4.310159999999996,
					631.0102400000001,
					232.99032,
					311.73024,
					232.99032
				]
			],
			"area": 73013.00148480001,
			"iscrowd": 0,
			"image_id": 1,
			"bbox": [
				311.73024,
				4.310159999999996,
				319.28000000000003,
				228.68016
			],
			"category_id": 50,
			"id": 2
		},
        ],
"categories": [
		{
			"id": 1,
			"name": "0",
			"supercategory": "0"
		},
		{
			"id": 2,
			"name": "1",
			"supercategory": "1"
		},
		{
			"id": 3,
			"name": "2",
			"supercategory": "2"
		},
        ]
}

 

1) info: 데이터셋의 메타 정보
- year: 데이터셋이 만들어진 연도 (2021).
- version: 데이터셋의 버전 (1.0).
- description: 데이터셋의 목적 ex) For object detection
- date_created: 데이터셋이 만들어진 날짜 (2021).

 

2) images: 이미지에 대한 정보
- date_captured (캡처 날짜)

- file_name (파일 이름)

- id (고유 식별자)

- height (높이)

- width (너비)

 

3) licenses: 데이터셋에 대한 라이센스 정보

- id: 라이센스의 고유 아이디
- name: 라이센스의 이름 ex) GNU General Public License v3.0
- url: 라이센스에 대한 URL


4) type: 데이터셋의 유형 ex)instances

 

5) annotations: 이미지에 대한 주석(annotations) 정보


- segmentation: 객체를 설명하는 다각형 좌표 배열
- area: 객체 영역의 면적.
- iscrowd: 객체가 모여 있는지 여부를 나타내는 플래그. (0:모여있지 않음. 1 :모여있음)

- image_id: 주석이 속한 이미지의 고유 식별자.
- bbox: 객체를 감싸는 경계 상자(bounding box)의 좌표 및 크기.
- category_id: 객체의 범주 식별자.
- id: 주석의 고유 식별자


6) categories: 객체 범주(category)에 대한 정보
- id: 범주의 고유 식별자.
- name: 범주의 이름.
- supercategory: 범주의 상위 범주

ex) category - cake , supercategory - food

 

 

* 학습에는 json 파일의 필요한 정보만 뽑아서 사용한다.

- image , annotations, categories

def filter_coco_data(coco, class_names):
    filtered_images = []
    filtered_annotations = []
    
    for class_name in class_names:
        cat_ids = coco.getCatIds(catNms=[class_name])
        img_ids = coco.getImgIds(catIds=cat_ids)
        ann_ids = coco.getAnnIds(catIds=cat_ids)
        
        images = coco.loadImgs(ids=img_ids)
        annotations = coco.loadAnns(ids=ann_ids)
        
        filtered_images.extend(images)
        filtered_annotations.extend(annotations)
    
    return filtered_images, filtered_annotations
with open(new_ann_file, 'w') as f:
    json.dump({
        'images': filtered_images,
        'annotations': filtered_annotations,
        'categories': coco.loadCats(coco.getCatIds())
    }, f)

 

https://situdy.tistory.com/86

 

[Object Detection] COCO 데이터셋을 이용한 교통수단 탐지

[교통 수단 Object Detection] 목표 YOLOv8n 을 사용하여 8개의 클래스 교통수단 Object Detection 카테고리 -bicycle - car - motorcycle - airplane - bus - train - truck - boat 데이터셋 - COCO dataset 중 val2017 사용 https://cocodat

situdy.tistory.com