Skip to content

Commit

Permalink
fixing TemporalDetection rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Jan 23, 2023
1 parent c4f6c8e commit 819366c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
25 changes: 15 additions & 10 deletions eta/core/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class AnnotationConfig(Config):
show_event_masks: (True) whether to render event segmentation masks, if
available
show_event_label_on_objects: (True) whether to render event labels as
attributes ob objects that belong to events
attributes on objects that belong to events
show_event_objects_in_same_color: (True) whether to render objects that
belong to events in the same color as their parent event
occluded_event_attr: ("occluded") the name of the boolean attribute
Expand Down Expand Up @@ -1315,8 +1315,8 @@ def _draw_event(img, event, annotation_config, color=None):
per_label_colors = annotation_config.per_event_label_colors
per_index_colors = annotation_config.per_event_index_colors

# If the event has no bounding box, return event attributes for rendering
# via another method
# If the event has no bounding box, return label and attributes for
# rendering via another method
return_attrs = not event.has_bounding_box

img_anno, attr_strs, event_color = _draw_bbox_with_attrs(
Expand Down Expand Up @@ -1497,6 +1497,8 @@ def _draw_bbox_with_attrs(
if return_now:
return img, [], None

non_rendered_attr_strs = []

# Scale alpha by confidence, if requested
if confidence_scaled_alpha and obj_or_event.confidence is not None:
bbox_alpha *= obj_or_event.confidence
Expand All @@ -1515,6 +1517,9 @@ def _draw_bbox_with_attrs(
per_index_colors=per_index_colors,
)

if return_attrs:
non_rendered_attr_strs.append(title_str)

# Choose box color
if color:
# Use manually specified color
Expand Down Expand Up @@ -1581,20 +1586,18 @@ def _draw_bbox_with_attrs(
show_attr_confidences,
)

# Return attributes instead of drawing them, if requested
if return_attrs:
return img_anno, attr_strs, bbox_color

# Draw attributes
if has_bounding_box and show_attrs and attr_strs:
if return_attrs:
non_rendered_attr_strs.extend(attr_strs)
elif has_bounding_box and show_attrs and attr_strs:
logger.debug("Rendering %d bbox attributes", len(attr_strs))

bounding_box = obj_or_event.bounding_box
img_anno = _draw_bbox_attrs(
img_anno, bounding_box, attr_strs, annotation_config
)

return img_anno, [], bbox_color
return img_anno, non_rendered_attr_strs, bbox_color


def _draw_bbox_attrs(img, bounding_box, attr_strs, annotation_config):
Expand Down Expand Up @@ -1963,7 +1966,9 @@ def _render_attrs(

attr_strs.append(
_render_attr_name_value(
attr, show_name=show_name, show_confidence=show_confidence,
attr,
show_name=show_name,
show_confidence=show_confidence,
)
)

Expand Down
11 changes: 5 additions & 6 deletions eta/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ def offset_object_indexes(self, offset):
devent.offset_object_indexes(offset)

def clear_object_indexes(self):
"""Clears the `index`es of all objects in all events in the container.
"""
"""Clears the `index`es of all objects in all events in the container."""
for devent in self:
devent.clear_object_indexes()

Expand Down Expand Up @@ -1294,8 +1293,7 @@ def offset_object_indexes(self, offset):
event.offset_object_indexes(offset)

def clear_object_indexes(self):
"""Clears the `index`es of all objects in all events in the container.
"""
"""Clears the `index`es of all objects in all events in the container."""
for event in self:
event.clear_object_indexes()

Expand Down Expand Up @@ -3229,6 +3227,8 @@ def _render_frame(self, frame_number, event_attrs, dobjs, in_place):
devent.label = event.label
if event.confidence is not None:
devent.confidence = event.confidence
if event.name is not None:
devent.name = event.name
if event.index is not None:
devent.index = event.index

Expand Down Expand Up @@ -3268,8 +3268,7 @@ def _get_event_attrs(self):


class VideoEventContainerFrameRenderer(etal.LabelsContainerFrameRenderer):
"""Class for rendering labels for a VideoEventContainer at the frame-level.
"""
"""Class for rendering labels for a VideoEventContainer at the frame-level."""

_LABELS_CLS = VideoEventContainer
_FRAME_LABELS_CLS = DetectedEventContainer
Expand Down
11 changes: 5 additions & 6 deletions eta/core/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ def offset_indexes(self, offset):
dobj.offset_index(offset)

def clear_indexes(self):
"""Clears the ``index`` of all objects in the container.
"""
"""Clears the ``index`` of all objects in the container."""
for dobj in self:
dobj.clear_index()

Expand Down Expand Up @@ -635,8 +634,7 @@ def iter_detections(self):

@property
def framewise_renderer_cls(self):
"""The :class:`eta.core.labels.LabelsFrameRenderer` used by this class.
"""
"""The :class:`eta.core.labels.LabelsFrameRenderer` used by this class."""
return VideoObjectFrameRenderer

@property
Expand Down Expand Up @@ -972,8 +970,7 @@ class VideoObjectContainer(

@property
def framewise_renderer_cls(self):
"""The :class:`eta.core.labels.LabelsFrameRenderer` used by this class.
"""
"""The :class:`eta.core.labels.LabelsFrameRenderer` used by this class."""
return VideoObjectContainerFrameRenderer

@property
Expand Down Expand Up @@ -2178,6 +2175,8 @@ def _render_frame(self, frame_number, obj_attrs, in_place):
dobj.label = self._obj.label
if self._obj.confidence is not None:
dobj.confidence = self._obj.confidence
if self._obj.name is not None:
dobj.name = self._obj.name
if self._obj.index is not None:
dobj.index = self._obj.index

Expand Down

0 comments on commit 819366c

Please sign in to comment.