def from_label(
        cls,
        label,
        metadata,
        image_id=None,
        category_id=None,
        keypoint=None,
        extra_attrs=True,
        id_attr=None,
        iscrowd="iscrowd",
        num_decimals=None,
        tolerance=None,
    ):
        """Creates a :class:`COCOObject` from a compatible
        :class:`fiftyone.core.labels.Label`.

        Args:
            label: a :class:`fiftyone.core.labels.Detection`,
                :class:`fiftyone.core.labels.Polyline`, or
                :class:`fiftyone.core.labels.Keypoint`
            metadata: a :class:`fiftyone.core.metadata.ImageMetadata` for the
                image
            image_id (None): an image ID
            category_id (None): the category ID for the object
            keypoint (None): an optional :class:`fiftyone.core.labels.Keypoint`
                containing keypoints to include for the object
            extra_attrs (True): whether to include extra attributes from the
                object. Supported values are:

                -   ``True``: include all extra attributes found
                -   ``False``: do not include extra attributes
                -   a name or list of names of specific attributes to include
            id_attr (None): the name of the attribute containing the annotation
                ID of the label, if any
            iscrowd ("iscrowd"): the name of the crowd attribute (the value is
                automatically set to 0 if the attribute is not present)
            num_decimals (None): an optional number of decimal places at which
                to round bounding box pixel coordinates. By default, no
                rounding is done
            tolerance (None): a tolerance, in pixels, when generating
                approximate polylines for instance masks. Typical values are
                1-3 pixels

        Returns:
            a :class:`COCOObject`
        """
        width = metadata.width
        height = metadata.height
        frame_size = (width, height)

        bbox = None
        segmentation = None
        keypoints = None
        area = None

        if isinstance(label, fol.Detection):
            x, y, w, h = label.bounding_box
            bbox = [x * width, y * height, w * width, h * height]

            if label.has_mask:
                segmentation = _instance_to_coco_segmentation(
                    label, frame_size, iscrowd=iscrowd, tolerance=tolerance
                )
        elif isinstance(label, fol.Polyline):
            points = np.concatenate(label.points, axis=0)
            x, y = points.min(axis=0)
            xmax, ymax = points.max(axis=0)
            w, h = xmax - x, ymax - y
            bbox = [x * width, y * height, w * width, h * height]

            segmentation = _polyline_to_coco_segmentation(
                label, frame_size, iscrowd=iscrowd
            )
        elif isinstance(label, fol.Keypoint):
            keypoints = _make_coco_keypoints(label, frame_size)
        else:
            raise ValueError("Unsupported label type %s" % type(label))

        if keypoint is not None:
            keypoints = _make_coco_keypoints(keypoint, frame_size)

        confidence = label.confidence

        if bbox is not None:
            if num_decimals is not None:
                bbox = [round(p, num_decimals) for p in bbox]

            area = bbox[2] * bbox[3]

        if id_attr is not None:
            _id = label.get_attribute_value(id_attr, None)
        else:
            _id = None

        _iscrowd = int(label.get_attribute_value(iscrowd, None) or 0)

        attributes = _get_attributes(label, extra_attrs)
        attributes.pop(id_attr, None)  # okay if `id_attr` is None
        attributes.pop(iscrowd, None)
        attributes.pop("area", None)
        attributes.pop("visible", None)

        return cls(
            id=_id,
            image_id=image_id,
            category_id=category_id,
            bbox=bbox,
            segmentation=segmentation,
            keypoints=keypoints,
            score=confidence,
            area=area,
            iscrowd=_iscrowd,
            **attributes,
        )
Creates a :class:`COCOObject` from a compatible
        :class:`fiftyone.core.labels.Label`.

        Args:
            label: a :class:`fiftyone.core.labels.Detection`,
                :class:`fiftyone.core.labels.Polyline`, or
                :class:`fiftyone.core.labels.Keypoint`
            metadata: a :class:`fiftyone.core.metadata.ImageMetadata` for the
                image
            image_id (None): an image ID
            category_id (None): the category ID for the object
            keypoint (None): an optional :class:`fiftyone.core.labels.Keypoint`
                containing keypoints to include for the object
            extra_attrs (True): whether to include extra attributes from the
                object. Supported values are:

                -   ``True``: include all extra attributes found
                -   ``False``: do not include extra attributes
                -   a name or list of names of specific attributes to include
            id_attr (None): the name of the attribute containing the annotation
                ID of the label, if any
            iscrowd ("iscrowd"): the name of the crowd attribute (the value is
                automatically set to 0 if the attribute is not present)
            num_decimals (None): an optional number of decimal places at which
                to round bounding box pixel coordinates. By default, no
                rounding is done
            tolerance (None): a tolerance, in pixels, when generating
                approximate polylines for instance masks. Typical values are
                1-3 pixels

        Returns:
            a :class:`COCOObject`
        
fiftyone/utils/coco.py