def METHOD_NAME(txt_path, json_path, xml_path):
    # create and init coco json, img set, and class set
    coco_json, class_set, image_set = init_json()
    ### collect img and ann info into coco json
    # read img_name in txt, e.g., 000005 for voc2007, 2008_000002 for voc2012
    img_txt = open(txt_path, 'r')
    img_line = img_txt.readline().strip()
    # loop xml 
    img_id = 0
    ann_id = 0
    while img_line:
        print('img_id:', img_id)
        # find corresponding xml
        xml_name = img_line.split('Annotations/', 1)[1]
        xml_file = os.path.join(xml_path, xml_name)
        if not os.path.exists(xml_file):
            print('{} is not exists.'.format(xml_name))
            img_line = img_txt.readline().strip()
            continue
        # decode xml
        tree = ET.parse(xml_file)
        root = tree.getroot()
        if root.tag != 'annotation':
            raise Exception(
                'xml {} root element should be annotation, rather than {}'.
                format(xml_name, root.tag))
        # init img and ann info
        bndbox = dict()
        size = dict()
        size['width'] = None
        size['height'] = None
        size['depth'] = None
        # filename
        fileNameNode = root.find('filename')
        file_name = fileNameNode.text
        # img size
        sizeNode = root.find('size')
        if not sizeNode:
            raise Exception('xml {} structure broken at size tag.'.format(
                xml_name))
        for subNode in sizeNode:
            size[subNode.tag] = int(subNode.text)
        # add img into json
        if file_name not in image_set:
            img_id += 1
            format_img_id = int("%04d" % img_id)
            # print('line 120. format_img_id:', format_img_id)
            image_item = getImgItem(file_name, size, img_id)
            image_set.add(file_name)
            coco_json['images'].append(image_item)
        else:
            raise Exception(' xml {} duplicated image: {}'.format(xml_name,
                                                                  file_name))
        ### add objAnn into json
        objectAnns = root.findall('object')
        for objectAnn in objectAnns:
            bndbox['xmin'] = None
            bndbox['xmax'] = None
            bndbox['ymin'] = None
            bndbox['ymax'] = None
            #add obj category
            object_name = objectAnn.find('name').text
            if object_name not in class_set:
                raise Exception('xml {} Unrecognized category: {}'.format(
                    xml_name, object_name))
            else:
                current_category_id = class_set[object_name]
            #add obj bbox ann
            objectBboxNode = objectAnn.find('bndbox')
            for coordinate in objectBboxNode:
                if bndbox[coordinate.tag] is not None:
                    raise Exception('xml {} structure corrupted at bndbox tag.'.
                                    format(xml_name))
                bndbox[coordinate.tag] = int(float(coordinate.text))
            bbox = []
            # x
            bbox.append(bndbox['xmin'])
            # y
            bbox.append(bndbox['ymin'])
            # w
            bbox.append(bndbox['xmax'] - bndbox['xmin'])
            # h
            bbox.append(bndbox['ymax'] - bndbox['ymin'])
            ann_id += 1
            ann_item = getAnnoItem(object_name, img_id, ann_id,
                                   current_category_id, bbox)
            coco_json['annotations'].append(ann_item)
        img_line = img_txt.readline().strip()
    print('Saving json.')
    json.dump(coco_json, open(json_path, 'w'))