Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

말랑코딩

coco dataset json 포맷 파헤치기(annotation) 본문

딥러닝

coco dataset json 포맷 파헤치기(annotation)

코랑이 2022. 2. 10. 16:12

딥러닝 분할, 분류, 검출 등의 코드 실습 시 가장 많이 쓰이는 오픈 데이터셋인 coco dataset을 다운받았다.

annoation은 json 형태로 돼있다.

이 형태로 나의 custom data 형태를 맞춰줘야하는 과정에서 헷갈리는 것들이 있어서 정리해본다.

 

아래는 coco128/instances_val2017.json 의 일부를 발췌해온 것이다.

{
	"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"
		},
        ]
}

 

 

위에서 실제로 검출에 필요한것만 간추려서 다시 쓰면 이렇다. (segmentation 등 불필요한 것 제외)

 


{
    "images": [
		{
			"file_name": "000000000001.jpg",
			"id": 1,
			"height": 480,
			"width": 640
		},
		{
			"file_name": "000000000002.jpg",
			"id": 2,
			"height": 426,
			"width": 640
		},
    ],
    "type": "instances",
	"annotations": [
		{
			"image_id": 1,
			"bbox": [
				1.0799999999999272,
				187.69008000000002,
				611.5897600000001,
				285.84000000000003
			],
			"category_id": 19,
			"id": 1
		},
		{
			"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"
		},
    ]
}

 

 

가장 헷갈렸던것, bbox 형태는 x1,y1,width,height 이다.

image_id = 1번의 bbox 를 모두 그려보니 아래 그림과 같았다.

lunch box 3개와 brocoli 1개에 대한 annotation 인듯하다.

 

 

또하나 알아야할 것은 "annotation" 에서 "image_id"는 어떤 이미지에 대한 annotation인지를 말하고,

그냥 "id"는 전체 annotation에서의 인덱스를 말한다.

'딥러닝' 카테고리의 다른 글

앵커 박스(Anchor box)  (0) 2022.02.10
docker 에서 yolox 데모 실행해보기(ubuntu 18.04)  (0) 2022.02.09
7-5. 풀링 계층 구현하기  (0) 2022.01.05
7-4. 합성곱 계층 구현하기  (0) 2022.01.05
7-3. 풀링 계층(Pooling layer)  (0) 2022.01.05
Comments