def xml2coco_test(file_list, img_root, save_path, start_ann_id=0):
    """Save annotations in coco-format.

    :param file_list: list of data annotation files.
    :param img_root: the root dir to load images.
    :param save_path: the path to save transformed annotation file.
    :param start_ann_id: the starting point to count the annotation id.
    """
    images = []
    annotations = []
    img_ids = []
    ann_ids = []

    ann_id = start_ann_id

    name2id = {
        'L_eye': 0,
        'R_eye': 1,
        'L_ear': 2,
        'R_ear': 3,
        'Nose': 4,
        'Throat': 5,
        'Tail': 6,
        'withers': 7,
        'L_F_elbow': 8,
        'R_F_elbow': 9,
        'L_B_elbow': 10,
        'R_B_elbow': 11,
        'L_F_knee': 12,
        'R_F_knee': 13,
        'L_B_knee': 14,
        'R_B_knee': 15,
        'L_F_paw': 16,
        'R_F_paw': 17,
        'L_B_paw': 18,
        'R_B_paw': 19
    }

    cat2id = {'cat': 1, 'cow': 2, 'dog': 3, 'horse': 4, 'sheep': 5}

    for file in file_list:
        data_anno = xmltodict.parse(open(file).read())['annotation']

        category_id = cat2id[data_anno['category']]

        img_id = category_id * 1000 + int(
            re.findall(r'\d+', data_anno['image'])[0])

        assert img_id not in img_ids

        # prepare images
        image_name = os.path.join('animalpose_image_part2',
                                  data_anno['category'], data_anno['image'])
        img = cv2.imread(os.path.join(img_root, image_name))

        image = {}
        image['id'] = img_id
        image['file_name'] = image_name
        image['height'] = img.shape[0]
        image['width'] = img.shape[1]

        images.append(image)
        img_ids.append(img_id)

        # prepare annotations
        keypoint_anno = data_anno['keypoints']['keypoint']
        keypoints = np.zeros([20, 3], dtype=np.float32)

        for kpt_anno in keypoint_anno:
            keypoint_name = kpt_anno['@name']
            keypoint_id = name2id[keypoint_name]

            visibility = int(kpt_anno['@visible'])

            if visibility == 0:
                continue
            else:
                keypoints[keypoint_id, 0] = float(kpt_anno['@x'])
                keypoints[keypoint_id, 1] = float(kpt_anno['@y'])
                keypoints[keypoint_id, 2] = 2

        anno = {}
        anno['keypoints'] = keypoints.reshape(-1).tolist()
        anno['image_id'] = img_id
        anno['id'] = ann_id
        anno['num_keypoints'] = int(sum(keypoints[:, 2] > 0))

        visible_bounds = data_anno['visible_bounds']
        anno['bbox'] = [
            float(visible_bounds['@xmin']),
            float(visible_bounds['@xmax']
                  ),  # typo in original xml: should be 'ymin'
            float(visible_bounds['@width']),
            float(visible_bounds['@height'])
        ]
        anno['iscrowd'] = 0
        anno['area'] = float(anno['bbox'][2] * anno['bbox'][3])
        anno['category_id'] = 1

        annotations.append(anno)
        ann_ids.append(ann_id)
        ann_id += 1

    cocotype = {}

    cocotype['info'] = {}
    cocotype['info'][
        'description'] = 'AnimalPose dataset Generated by MMPose Team'
    cocotype['info']['version'] = '1.0'
    cocotype['info']['year'] = time.strftime('%Y', time.localtime())
    cocotype['info']['date_created'] = time.strftime('%Y/%m/%d',
                                                     time.localtime())

    cocotype['images'] = images
    cocotype['annotations'] = annotations

    keypoints_info, skeleton_info, category_info = get_anno_info()

    cocotype['categories'] = category_info

    os.makedirs(os.path.dirname(save_path), exist_ok=True)
    json.dump(cocotype, open(save_path, 'w'), indent=4)
    print('=========================================================')
    print('number of images:', len(img_ids))
    print('number of annotations:', len(ann_ids))
    print(f'done {save_path}')
Save annotations in coco-format.

    :param file_list: list of data annotation files.
    :param img_root: the root dir to load images.
    :param save_path: the path to save transformed annotation file.
    :param start_ann_id: the starting point to count the annotation id.
    
mmpose/tools/dataset_converters/parse_animalpose_dataset.py