最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

json轉(zhuǎn)coco格式

2022-12-03 10:24 作者:熊二愛(ài)光頭強(qiáng)丫  | 我要投稿

import json
import glob

def build_basic_dict():
? ?basic_dict = {}

? ?info = {}
? ?description = 'small_person_keypoints'
? ?author = 'lishaohua'
? ?info.update({'description':description,'author':author})
? ?basic_dict.update({'info':info})

? ?categories={}
? ?categories.update({'supercategory':'person','id':1,'name':'person'})
? ?keypoints = ["nose",
? ? ? ? ? ? ? ? "left_eye","right_eye",
? ? ? ? ? ? ? ? "left_ear","right_ear",
? ? ? ? ? ? ? ? "left_shoulder","right_shoulder",
? ? ? ? ? ? ? ? "left_elbow","right_elbow",
? ? ? ? ? ? ? ? "left_wrist","right_wrist",
? ? ? ? ? ? ? ? "left_hip","right_hip",
? ? ? ? ? ? ? ? "left_knee","right_knee",
? ? ? ? ? ? ? ? "left_ankle","right_ankle"]
? ?skeleton = [[16,14],
? ? ? ? ? ? ? ?[14,12],
? ? ? ? ? ? ? ?[17,15],
? ? ? ? ? ? ? ?[15,13],
? ? ? ? ? ? ? ?[12,13],
? ? ? ? ? ? ? ?[6,12],
? ? ? ? ? ? ? ?[7,13],
? ? ? ? ? ? ? ?[6,7],
? ? ? ? ? ? ? ?[6,8],
? ? ? ? ? ? ? ?[7,9],
? ? ? ? ? ? ? ?[8,10],
? ? ? ? ? ? ? ?[9,11],
? ? ? ? ? ? ? ?[2,3],
? ? ? ? ? ? ? ?[1,2],
? ? ? ? ? ? ? ?[1,3],
? ? ? ? ? ? ? ?[2,4],
? ? ? ? ? ? ? ?[3,5],
? ? ? ? ? ? ? ?[4,6],
? ? ? ? ? ? ? ?[5,7]]
? ?categories.update({'keypoints':keypoints,'skeleton':skeleton})
? ?basic_dict.update({'categories':categories})
? ?return basic_dict

def build_images(img_lists,json_lists):
? ?images=[]
? ?for name in img_lists:
? ? ? ?file_name = name.split('\\')[7]
? ? ? ?id = int(file_name.split('.')[0])
? ? ? ?for j in json_lists:
? ? ? ? ? ?with open(j, 'r') as f:
? ? ? ? ? ? ? ?f = json.load(f)
? ? ? ? ? ? ? ?if file_name == f['imagePath']:
? ? ? ? ? ? ? ? ? ?height = f['imageHeight']
? ? ? ? ? ? ? ? ? ?width = f['imageWidth']
? ? ? ? ? ? ? ? ? ?image={}
? ? ? ? ? ? ? ? ? ?image.update({'file_name':file_name,'height':height,'width':width,'id':id})
? ? ? ? ? ? ? ? ? ?images.append(image)
? ?return images

def build_annotations(img_lists,json_lists):
? ?annotations_dict = {}
? ?annotations_dicts =[]
? ?ann_id = 0
? ?for i in json_lists:
? ? ? ?with open(i, 'r') as f:
? ? ? ? ? ?shape = json.load(f)['shapes']
? ? ? ? ? ?num_person = int(len(shape) / (17 ? 1))
? ? ? ? ? ?keypoints= []
? ? ? ? ? ?bbox = []
? ? ? ? ? ?num_joint=0
? ? ? ? ? ?for per_joint in shape:
? ? ? ? ? ? ? ?if per_joint['group_id'] == 0:
? ? ? ? ? ? ? ? ? ?x,y,z = 0,0,0
? ? ? ? ? ? ? ? ? ?keypoints.extend([x,y,z])
? ? ? ? ? ? ? ? ? ?num_joint ?=1
? ? ? ? ? ? ? ?if 'bbox' in per_joint['label']:
? ? ? ? ? ? ? ? ? ?xmin,ymin = enumerate(per_joint['points'][0])
? ? ? ? ? ? ? ? ? ?xmax,ymax = enumerate(per_joint['points'][1])
? ? ? ? ? ? ? ? ? ?bbox.extend([xmin[1],ymin[1],xmax[1]-xmin[1],ymax[1]-ymin[1]])
? ? ? ? ? ? ? ?if per_joint['group_id'] == 1:
? ? ? ? ? ? ? ? ? ?x,y = enumerate(per_joint['points'][0])
? ? ? ? ? ? ? ? ? ?keypoints.extend([x[1],y[1],per_joint['group_id']])
? ? ? ? ? ? ? ?if per_joint['group_id'] == 2 and 'bbox' not in per_joint['label']:
? ? ? ? ? ? ? ? ? ?x, y = enumerate(per_joint['points'][0])
? ? ? ? ? ? ? ? ? ?keypoints.extend([x[1], y[1], per_joint['group_id']])
? ? ? ? ? ?num_keypoints = 17 - num_joint
? ? ? ? ? ?image_id = int(i.split('\\')[-1].split('.')[0])
? ? ? ? ? ?category_id = 1
? ? ? ? ? ?for j in range(num_person):
? ? ? ? ? ? ? ?ann_id ?= 1
? ? ? ? ? ? ? ?annotations_dict.update({'num_keypoints':num_keypoints,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'area':int(bbox[2] * bbox[3]),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'iscrowd': int(0),
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'keypoints':keypoints[16*3*j:16*3*(j 1) 3],
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'image_id':image_id,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'bbox':bbox[0:4],
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'category_id':category_id,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'id':int(ann_id-1)})
? ? ? ? ? ? ? ?a = annotations_dict.copy()
? ? ? ? ? ? ? ?annotations_dicts.append(a)
? ?return annotations_dicts

file_path = 'C:\\Users\\zstu\\Desktop\\smallperson\\images\\val2017\\' ?#需要修改
json_lists = glob.glob(file_path + '\\*.json')
img_lists = glob.glob(file_path + '\\*.jpg')

for json_name in json_lists:
? ?with open(json_name,'r') as f:
? ? ? ?f = json.load(f)

? ?basic_dicts = build_basic_dict()
? ?images_dicts = build_images(img_lists,json_lists)
? ?annotations_dicts = build_annotations(img_lists,json_lists)
? ?tinyperson = {}
? ?tinyperson.update({'info':basic_dicts['info'],'images':images_dicts,'annotations':annotations_dicts,'categories':[basic_dicts['categories']]})
? ?json.dump(tinyperson,open('C:\\Users\\zstu\\Desktop\\smallperson\\annotations\\tinyperson.json','w'),indent=4) #需要修改


json轉(zhuǎn)coco格式的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
贡觉县| 上饶市| 迁西县| 西充县| 台中县| 鄂尔多斯市| 萨迦县| 新源县| 石首市| 呼玛县| 泾川县| 高青县| 同仁县| 上饶县| 丹江口市| 论坛| 黄平县| 精河县| 瑞昌市| 云南省| 六安市| 乌苏市| 平山县| 琼海市| 平原县| 灯塔市| 米林县| 五寨县| 萍乡市| 嵊泗县| 南郑县| 金华市| 永福县| 莱阳市| 马山县| 江口县| 大竹县| 定襄县| 石嘴山市| 金阳县| 黔西|