import xml.etree.ElementTree as ET
import os
import json
coco =dict()
coco['images']=[]
coco['type']='instances'
coco['annotations']=[]
coco['categories']=[]
category_set =dict()
image_set =set()
category_item_id =-1
image_id =20180000000
annotation_id =0defaddCatItem(name):global category_item_id
category_item =dict()
category_item['supercategory']='none'
category_item_id +=1
category_item['id']= category_item_id
category_item['name']= name
coco['categories'].append(category_item)
category_set[name]= category_item_id
return category_item_id
defaddImgItem(file_name, size):global image_id
if file_name isNone:raise Exception('Could not find filename tag in xml file.')if size['width']isNone:raise Exception('Could not find width tag in xml file.')if size['height']isNone:raise Exception('Could not find height tag in xml file.')
image_id +=1
image_item =dict()
image_item['id']= image_id
image_item['file_name']= file_name
image_item['widt