一个汽车图标的训练集:train.json
[{"items": [{"label_id": "0028", "bbox": [240, 198, 268, 222]}], "image_id": "500_0Ak1_rpeQjUJL_nbKBYijb.jpg"},
{"items": [{"label_id": "0028", "bbox": [49, 30, 117, 88]}, {"label_id": "0030", "bbox": [463, 102, 517, 157]}], "image_id": "500_0kzV_rqaMeFtu_qgdDh4LB.jpg"},
....
]
#-*- coding: utf-8 -*-
import json
# 打开json 文件
f=open('E:/BDCI/BDCI2017/train/train.json','r')
# dumps 将字典转化为字符串序列化
# loads 将字符串转化为字典
# dump 将数据写入json文件中
# load 将字符串转换为数据类型。
image_label=[]
image_bbox=[]
image_name=[]
train=json.load(f)
for i in train:
# 一个图中可能有多个汽车标志
num=len(i['items'])
for k in range(num):
image_label.append(i['items'][k]['label_id'])
image_bbox.append(i['items'][k]['bbox'])
image_name.append(i['image_id']) f.close()