import json
import shutil
import os
# JSON 파일 읽기
def read_json_file(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
return data
# 파일 경로
for i in ["val", "train"]:
file_path = f'datasets/ds_01HPZPHEWSATM9C9ZDX70V0F7X/sub_{i}.json'
if i == "val":
i = "test"
# JSON 파일 읽기
json_data = read_json_file(file_path)
print(json_data['categories'])
from pycocotools.coco import COCO
coco = COCO(file_path)
coco.loadAnns(coco.getAnnIds([1]))
import jsonlines
# jsonlines 파일을 쓰기 모드로 열기
with jsonlines.open(f"datasets/cache_images/ds_01HPZPHEWSATM9C9ZDX70V0F7X/{i}/metadata.jsonl", mode="w") as writer:
# COCO 데이터셋의 모든 이미지 ID에 대해 반복
for img_id in coco.getImgIds():
# 이미지 ID에 해당하는 이미지 정보 로드
image_dict = coco.loadImgs([img_id])[0]
# 이미지 ID에 해당하는 모든 주석 로드
anns = coco.loadAnns(coco.getAnnIds([img_id]))
# R…