예제 #1
0
파일: kitti.py 프로젝트: zfyong/fiftyone
def _parse_kitti_detection_row(row, frame_size):
    attributes = {}

    label = row[0]

    attributes["truncated"] = fol.NumericAttribute(value=float(row[1]))
    attributes["occluded"] = fol.NumericAttribute(value=int(row[2]))
    attributes["alpha"] = fol.NumericAttribute(value=float(row[3]))

    width, height = frame_size
    xtl, ytl, xbr, ybr = map(float, row[4:8])
    bounding_box = [
        xtl / width,
        ytl / height,
        (xbr - xtl) / width,
        (ybr - ytl) / height,
    ]

    try:
        attributes["dimensions"] = fol.VectorAttribute(
            value=np.asarray(map(float, row[8:11]))
        )
    except IndexError:
        pass

    try:
        attributes["location"] = fol.VectorAttribute(
            value=np.asarray(map(float, row[11:14]))
        )
    except IndexError:
        pass

    try:
        attributes["rotation_y"] = fol.NumericAttribute(value=float(row[14]))
    except IndexError:
        pass

    try:
        confidence = float(row[15])
    except IndexError:
        confidence = None

    return fol.Detection(
        label=label,
        bounding_box=bounding_box,
        confidence=confidence,
        attributes=attributes,
    )
예제 #2
0
    def to_detection(self, frame_size, classes=None, supercategory_map=None):
        """Returns a :class:`fiftyone.core.labels.Detection` representation of
        the object.

        Args:
            frame_size: the ``(width, height)`` of the image
            classes (None): the list of classes
            supercategory_map (None): a dict mapping class names to
                supercategories

        Returns:
            a :class:`fiftyone.core.labels.Detection`
        """
        if classes:
            label = classes[self.category_id]
        else:
            label = str(self.category_id)

        width, height = frame_size
        x, y, w, h = self.bbox
        bounding_box = [x / width, y / height, w / width, h / height]

        detection = fol.Detection(label=label, bounding_box=bounding_box)

        if supercategory_map is not None:
            supercategory = supercategory_map.get(label, None)
        else:
            supercategory = None

        if supercategory is not None:
            # pylint: disable=unsupported-assignment-operation
            detection.attributes["supercategory"] = fol.CategoricalAttribute(
                value=supercategory)

        if self.area is not None:
            # pylint: disable=unsupported-assignment-operation
            detection.attributes["area"] = fol.NumericAttribute(
                value=self.area)

        if self.iscrowd is not None:
            # pylint: disable=unsupported-assignment-operation
            detection.attributes["iscrowd"] = fol.NumericAttribute(
                value=self.iscrowd)

        # @todo parse `segmentation`

        return detection
예제 #3
0
    def _parse_attribute(self, value):
        if etau.is_str(value):
            return fol.CategoricalAttribute(value=value)

        if isinstance(value, bool):
            return fol.BooleanAttribute(value=value)

        if etau.is_numeric(value):
            return fol.NumericAttribute(value=value)

        return fol.Attribute(value=value)
예제 #4
0
파일: cvat.py 프로젝트: xibeiwind/fiftyone
    def to_attribute(self):
        """Returns a :class:`fiftyone.core.labels.Attribute` representation of
        the attribute.

        Returns:
            a :class:`fiftyone.core.labels.Attribute`
        """
        if isinstance(self.value, bool):
            return fol.BooleanAttribute(value=self.value)

        if etau.is_numeric(self.value):
            return fol.NumericAttribute(value=self.value)

        return fol.CategoricalAttribute(value=self.value)