def convert_to_coco(self, input_json: str, output_json: str):
        """Convert `input_json` to COCO format and save in `output_json`.

        Args:
            input_json (str): The path of Label Studio format JSON file.
            output_json (str): The path of the output COCO JSON file.
        """

        def add_image(images, width, height, image_id, image_path):
            images.append({
                'width': width,
                'height': height,
                'id': image_id,
                'file_name': image_path,
            })
            return images

        output_path = pathlib.Path(output_json)
        output_path.parent.mkdir(parents=True, exist_ok=True)

        images = list()
        annotations = list()

        with open(input_json, 'r') as f:
            ann_list = json.load(f)

        for item_idx, item in enumerate(ann_list):
            # each image is an item
            image_name = item['file_upload']
            image_id = len(images)
            width, height = None, None

            # skip tasks without annotations
            if not item['annotations']:
                logger.warning('No annotations found for item #' +
                               str(item_idx))
                continue

            kp_num = 0
            for i, label in enumerate(item['annotations'][0]['result']):
                category_name = None

                # valid label
                for key in [
                        'rectanglelabels', 'polygonlabels', 'labels',
                        'keypointlabels'
                ]:
                    if key == label['type'] and len(label['value'][key]) > 0:
                        category_name = label['value'][key][0]
                        break

                if category_name is None:
                    logger.warning('Unknown label type or labels are empty')
                    continue

                if not height or not width:
                    if 'original_width' not in label or \
                            'original_height' not in label:
                        logger.debug(
                            f'original_width or original_height not found'
                            f'in {image_name}')
                        continue

                    # get height and width info from annotations
                    width, height = label['original_width'], label[
                        'original_height']
                    images = add_image(images, width, height, image_id,
                                       image_name)

                category_id = self.category_name_to_id[category_name]

                annotation_id = len(annotations)

                if 'rectanglelabels' == label['type'] or 'labels' == label[
                        'type']:

                    x = label['value']['x']
                    y = label['value']['y']
                    w = label['value']['width']
                    h = label['value']['height']

                    x = x * label['original_width'] / 100
                    y = y * label['original_height'] / 100
                    w = w * label['original_width'] / 100
                    h = h * label['original_height'] / 100

                    # rect annotation should be later than keypoints
                    annotations[-1]['bbox'] = [x, y, w, h]
                    annotations[-1]['area'] = w * h
                    annotations[-1]['num_keypoints'] = kp_num

                elif 'polygonlabels' == label['type']:
                    points_abs = [(x / 100 * width, y / 100 * height)
                                  for x, y in label['value']['points']]
                    x, y = zip(*points_abs)

                    x1, y1, x2, y2 = min(x), min(y), max(x), max(y)

                    # calculate bbox and area from polygon's points
                    # which may be different with rect annotation
                    bbox = [x1, y1, x2 - x1, y2 - y1]
                    area = float(0.5 * np.abs(
                        np.dot(x, np.roll(y, 1)) - np.dot(y, np.roll(x, 1))))

                    # polygon label should be later than keypoints
                    annotations[-1]['segmentation'] = [[
                        coord for point in points_abs for coord in point
                    ]]
                    annotations[-1]['bbox'] = bbox
                    annotations[-1]['area'] = area
                    annotations[-1]['num_keypoints'] = kp_num

                elif 'keypointlabels' == label['type']:
                    x = label['value']['x'] * label['original_width'] / 100
                    y = label['value']['y'] * label['original_height'] / 100

                    # there is no method to annotate visible in Label Studio
                    # so the keypoints' visible code will be 2 except (0,0)
                    if x == y == 0:
                        current_kp = [x, y, 0]
                        kp_num_change = 0
                    else:
                        current_kp = [x, y, 2]
                        kp_num_change = 1

                    # create new annotation in coco
                    # when the keypoint is the first point of an instance
                    if i == 0 or item['annotations'][0]['result'][
                            i - 1]['type'] != 'keypointlabels':
                        annotations.append({
                            'id': annotation_id,
                            'image_id': image_id,
                            'category_id': category_id,
                            'keypoints': current_kp,
                            'ignore': 0,
                            'iscrowd': 0,
                        })
                        kp_num = kp_num_change
                    else:
                        annotations[-1]['keypoints'].extend(current_kp)
                        kp_num += kp_num_change

        with io.open(output_json, mode='w', encoding='utf8') as fout:
            json.dump(
                {
                    'images': images,
                    'categories': self.categories,
                    'annotations': annotations,
                    'info': {
                        'year': datetime.now().year,
                        'version': '1.0',
                        'description': '',
                        'contributor': 'Label Studio',
                        'url': '',
                        'date_created': str(datetime.now()),
                    },
                },
                fout,
                indent=2,
            )
Convert `input_json` to COCO format and save in `output_json`.

        Args:
            input_json (str): The path of Label Studio format JSON file.
            output_json (str): The path of the output COCO JSON file.
        
mmpose/tools/dataset_converters/labelstudio2coco.py