anno_coco2voc.py create many empty folder
huipengzhang opened this issue · comments
when convert coco annotation json file to VOC xml files,create many empty folder ,why?
any update on this?? facing the same issue.
Check your json annotation file. It should be like instances_train2014.json
downloaded from 2014 Train/Val annotations [241MB] and make sure your download is complete. @huipengzhang @AlgorTroy
Not sure if this is you, but I was attempting to run the script with Python 3.6. When I converted back to Python 2.7, everything seemed to work... at least it created files. :)
Thank you very much !It's ok now! @CasiaFan @fractalbass
I was facing the same issue. So I solved as below.
def parse_instance(content, outdir):
categories = {d['id']: d['name'] for d in content['categories']}
# merge images and annotations: id in images vs image_id in annotations
merged_info_list = map(cytoolz.merge, cytoolz.join('id', content['images'], 'image_id', content['annotations']))
list = [] // added this_1
# convert category id to name
for instance in merged_info_list:
instance['category_id'] = categories[instance['category_id']]
list.append(instance) // added this_2
# group by filename to pool all bbox in same file
for name, groups in cytoolz.groupby('file_name', list).items(): // modified to list
Modified the following function. It works now coco2017
def parse_keypoints(content, outdir):
keypoints = dict(zip(range(1, len(content['categories'][0]['keypoints'])+1), content['categories'][0]['keypoints']))
merged_info_list = list(map(cytoolz.merge, cytoolz.join('id', content['images'], 'image_id', content['annotations'])))
# convert category name to person
print('keypoints ', keypoints)
for keypoint in merged_info_list:
keypoint['category_id'] = "person"
# group by filename to pool all bbox and keypoint in same file
for name, groups in cytoolz.groupby('file_name', merged_info_list).items():
print(name)
filename = os.path.join(outdir, os.path.splitext(name)[0]+".xml")
anno_tree = keypoints2xml_base(groups[0])
for group in groups:
anno_tree = keypoints2xml_object(group, anno_tree, keypoints, bbox_type="xyxy")
# anno_tree.append(keypoints2xml_object(group, anno_tree, keypoints, bbox_type="xyxy"))
etree.ElementTree(anno_tree).write(filename, pretty_print=True)
print("Formating keypoints xml file {} done!".format(name))