image object를 json으로 변환하는 과정

youngseojeon·2022년 1월 28일
0

일단 이 딥러닝에서 dataset을 만들 때 이 json을 많이 사용한다.

우선 이번 AI spark 챌린지에서 다운받은 돼지와 관련된 json 자료를 visual studio 2015로 열어보면 이런 코드로 이루어져 있음을 알 수 있는데,

일단 사진의 정보가 나와있음을 알 수 있다. 어떤 정보냐 하면
1. 사진의 width와 height
2. 농장 장소의 이름은 무엇인가?
3. 그리고 농장의 환경은 어떻게 되어 있는지(열려 있는지 닫혀 있는지?)
4. 시간은 낮과 밤 중 언제인지
5. annotation에는 bbox와 segmentation 정보가 있고, category_id가 있는데 이는 아마도 밑에 있는 정보들 1:살찐 돼지 2:어린 돼지 3:암퇘지 로 나누는 것으로 보인다.

이제 이 정보들을 어떻게 가공하면 좋을지 고민을 더 해봐야 겠다.!

{"label_info": {"image": {"file_name": "livestock_pig_bbox_000001.jpg", "width": 1920, "height": 1080, "farm_name": "Asan", "farm_env": "open", "time": "daytime"}, "annotations": [{"bbox": [240, 2, 427, 164], "category_id": 1}, {"bbox": [831, 186, 1205, 610], "category_id": 1}, {"bbox": [1162, 468, 1507, 827], "category_id": 1}, {"bbox": [1234, 723, 1591, 959], "category_id": 1}, {"bbox": [1020, 3, 1462, 163], "category_id": 1}, {"bbox": [344, 50, 654, 390], "category_id": 1}, {"bbox": [375, 223, 675, 610], "category_id": 1}, {"bbox": [583, 421, 899, 843], "category_id": 1}, {"bbox": [870, 732, 1308, 969], "category_id": 1}, {"bbox": [678, 116, 976, 469], "category_id": 1}, {"bbox": [863, 877, 1276, 1013], "category_id": 1}, {"bbox": [316, 641, 635, 928], "category_id": 1}, {"bbox": [586, 0, 831, 433], "category_id": 1}], "categories": [{"supercategory": "livestock_pig", "id": 1, "name": "fat_pig"}, {"supercategory": "livestock_pig", "id": 2, "name": "weaning_pig"}, {"supercategory": "livestock_pig", "id": 3, "name": "sow"}]}}

json 파일 속 정보들을 가져오는 방법은 무엇일까?
예를 들어 이런 식으로 출력할 수 있다.

import json
import urllib.request as request

json_str = request(urlopen("무슨무슨 깃허브 레포터리").read()
output = json.loads(json_str)

for item in output:
	print(item["name"])
    print(item["full_name"])
    print(item["owner"]["login"]
    
json.dumps()

이런 식으로 [][]이렇게 차례대로 가져올 수 있다는 것!!

profile
youngseo-computerblog.tistory.com 을 사용하고 있습니다.

0개의 댓글