Example #1
0
def _make_attribute(name, value):
    if isinstance(value, bool):
        return etad.BooleanAttribute(name, value)

    if etau.is_numeric(value):
        return etad.NumericAttribute(name, value)

    return etad.CategoricalAttribute(name, value)
Example #2
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)
Example #3
0
    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)
Example #4
0
    def to_eta_attribute(self):
        """Returns an ``eta.core.data.Attribute`` representation of the
        attribute.

        Returns:
            an ``eta.core.data.Attribute``
        """
        if isinstance(self.value, bool):
            return etad.BooleanAttribute(self.name, self.value)

        if etau.is_numeric(self.value):
            return etad.NumericAttribute(self.name, self.value)

        return etad.CategoricalAttribute(self.name, self.value)
Example #5
0
def _to_eta_attributes(attributes):
    attrs = etad.AttributeContainer()
    for attr_name, attr in attributes.items():
        attr_value = attr.value
        if isinstance(attr_value, bool):
            _attr = etad.BooleanAttribute(attr_name, attr_value)
        elif etau.is_numeric(attr_value):
            _attr = etad.NumericAttribute(attr_name, attr_value)
        else:
            _attr = etad.CategoricalAttribute(attr_name, str(attr_value))

        attrs.add(_attr)

    return attrs
Example #6
0
    def to_detected_object(self, name=None):
        """Returns an ``eta.core.objects.DetectedObject`` representation of
        this instance.

        Args:
            name (None): the name of the label field

        Returns:
            an ``eta.core.objects.DetectedObject``
        """
        label = self.label

        # pylint: disable=unpacking-non-sequence
        tlx, tly, w, h = self.bounding_box
        brx = tlx + w
        bry = tly + h
        bounding_box = etag.BoundingBox.from_coords(tlx, tly, brx, bry)

        confidence = self.confidence

        # pylint: disable=no-member
        attrs = etad.AttributeContainer()
        for attr_name, attr in self.attributes.items():
            attr_value = attr.value
            if isinstance(attr_value, bool):
                _attr = etad.BooleanAttribute(attr_name, attr_value)
            elif etau.is_numeric(attr_value):
                _attr = etad.NumericAttribute(attr_name, attr_value)
            else:
                _attr = etad.CategoricalAttribute(attr_name, str(attr_value))

            attrs.add(_attr)

        return etao.DetectedObject(
            label=label,
            bounding_box=bounding_box,
            confidence=confidence,
            name=name,
            attrs=attrs,
        )