Exemple #1
0
 def log_image_with_boxes(
     self,
     tensor_image,
     tensor_boxes,
     name=None,
     step=None,
     timestamp=None,
     rescale=1,
     dataformats="CHW",
 ):
     name = name or "figure"
     asset_path = get_asset_path(
         run_path=self.artifacts_path,
         kind=V1ArtifactKind.IMAGE,
         name=name,
         step=step,
     )
     event_value = events_processors.image_boxes(
         asset_path=asset_path,
         tensor_image=tensor_image,
         tensor_boxes=tensor_boxes,
         rescale=rescale,
         dataformats=dataformats,
     )
     if event_value == UNKNOWN:
         return
     logged_event = LoggedEventSpec(
         name=name,
         kind=V1ArtifactKind.IMAGE,
         event=V1Event(timestamp=timestamp, step=step, image=event_value),
     )
     self._event_logger.add_event(logged_event)
 def test_image_with_boxes(self):
     event = image_boxes(
         asset_path=self.asset_path,
         tensor_image=tensor_np(shape=(3, 32, 32)),
         tensor_boxes=np.array([[10, 10, 40, 40]]),
     )
     assert event.path == self.asset_path
     assert os.path.exists(self.asset_path) is True
Exemple #3
0
    def log_image_with_boxes(
        self,
        tensor_image,
        tensor_boxes,
        name=None,
        step=None,
        timestamp=None,
        rescale=1,
        dataformats="CHW",
    ):
        """Logs an image with bounding boxes.

        ```python
        >>> log_image_with_boxes(
        >>>     name="my_image",
        >>>     tensor_image=np.arange(np.prod((3, 32, 32)), dtype=float).reshape((3, 32, 32)),
        >>>     tensor_boxes=np.array([[10, 10, 40, 40]]),
        >>> )
        ```

        Args:
            tensor_image: numpy.array or str: Image data or file name
            tensor_boxes: numpy.array or str: Box data (for detected objects)
                        box should be represented as [x1, y1, x2, y2]
            name: str, name of the image
            step: int, optional
            timestamp: datetime, optional
            rescale: int, optional
            dataformats: str, optional
        """
        self._log_has_events()

        name = name or "figure"
        asset_path = get_asset_path(
            run_path=self._artifacts_path,
            kind=V1ArtifactKind.IMAGE,
            name=name,
            step=step,
        )
        asset_rel_path = os.path.relpath(asset_path, self._artifacts_path)
        event_value = events_processors.image_boxes(
            asset_path=asset_path,
            tensor_image=tensor_image,
            tensor_boxes=tensor_boxes,
            rescale=rescale,
            dataformats=dataformats,
            asset_rel_path=asset_rel_path,
        )
        if event_value == UNKNOWN:
            return
        logged_event = LoggedEventSpec(
            name=name,
            kind=V1ArtifactKind.IMAGE,
            event=V1Event.make(timestamp=timestamp,
                               step=step,
                               image=event_value),
        )
        self._event_logger.add_event(logged_event)