def _make_attributes(d): attrs = etad.AttributeContainer() for name, value in d.items(): attr = _make_attribute(name, value) attrs.add(attr) return attrs
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(): attrs.add(etad.CategoricalAttribute(attr_name, attr.value)) return etao.DetectedObject( label=label, bounding_box=bounding_box, confidence=confidence, name=name, attrs=attrs, )
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
def to_detected_object(self, frame_size): """Returns a ``eta.core.objects.DetectedObject`` representation of the box. Args: frame_size: the ``(width, height)`` of the image Returns: a ``eta.core.objects.DetectedObject`` """ label = self.label bounding_box = etag.BoundingBox.from_abs_coords(self.xtl, self.ytl, self.xbr, self.ybr, frame_size=frame_size) attrs = etad.AttributeContainer( attrs=[a.to_eta_attribute() for a in self.attributes]) return etao.DetectedObject(label=label, bounding_box=bounding_box, attrs=attrs)