예제 #1
0
 def test_video(self):
     asset_path = self.asset_path + ".gif"
     event = video(asset_path=asset_path,
                   tensor=tensor_np(shape=(4, 3, 1, 8, 8)))
     assert event.path == asset_path
     assert os.path.exists(asset_path) is True
     event = video(asset_path=asset_path,
                   tensor=tensor_np(shape=(16, 48, 1, 28, 28)))
     assert event.path == asset_path
     assert os.path.exists(asset_path) is True
     event = video(asset_path=asset_path,
                   tensor=tensor_np(shape=(20, 7, 1, 8, 8)))
     assert event.path == asset_path
     assert os.path.exists(asset_path) is True
예제 #2
0
    def log_video(self,
                  data,
                  name=None,
                  fps=4,
                  step=None,
                  timestamp=None,
                  content_type=None):
        self._log_dashboard()

        is_file = isinstance(data, str) and os.path.exists(data)
        content_type = content_type or "gif"
        if is_file:
            name = name or os.path.basename(data)
            content_type = get_path_extension(filepath=data) or content_type
        else:
            name = name or "video"

        asset_path = get_asset_path(
            run_path=self.artifacts_path,
            kind=V1ArtifactKind.VIDEO,
            name=name,
            step=step,
            ext=content_type,
        )
        asset_rel_path = os.path.relpath(asset_path, self.artifacts_path)
        if is_file:
            event_value = events_processors.video_path(
                from_path=data,
                asset_path=asset_path,
                content_type=content_type,
                asset_rel_path=asset_rel_path,
            )
        else:
            event_value = events_processors.video(
                asset_path=asset_path,
                tensor=data,
                fps=fps,
                content_type=content_type,
                asset_rel_path=asset_rel_path,
            )

        if event_value == UNKNOWN:
            return

        logged_event = LoggedEventSpec(
            name=name,
            kind=V1ArtifactKind.VIDEO,
            event=V1Event.make(timestamp=timestamp,
                               step=step,
                               video=event_value),
        )
        self._event_logger.add_event(logged_event)
예제 #3
0
파일: run.py 프로젝트: yangjun1994/polyaxon
    def log_video(self,
                  data,
                  name=None,
                  fps=4,
                  step=None,
                  timestamp=None,
                  content_type=None):
        """Logs a video.

        ```python
        >>> log_video("path/to/my_video1"),
        >>> log_video(name="my_vide2", data=np.arange(np.prod((4, 3, 1, 8, 8)), dtype=float).reshape((4, 3, 1, 8, 8)))  # noqa
        ```

        Args:
            data: video data or str.
            name: str, optional, if data is a filepath the name will be the name of the file
            fps: int, optional, frames per second
            step: int, optional
            timestamp: datetime, optional
            content_type: str, optional, default "gif"
        """
        self._log_has_events()

        is_file = isinstance(data, str) and os.path.exists(data)
        content_type = content_type or "gif"
        if is_file:
            name = name or os.path.basename(data)
            content_type = get_path_extension(filepath=data) or content_type
        else:
            name = name or "video"

        asset_path = get_asset_path(
            run_path=self._artifacts_path,
            kind=V1ArtifactKind.VIDEO,
            name=name,
            step=step,
            ext=content_type,
        )
        asset_rel_path = os.path.relpath(asset_path, self._artifacts_path)
        if is_file:
            event_value = events_processors.video_path(
                from_path=data,
                asset_path=asset_path,
                content_type=content_type,
                asset_rel_path=asset_rel_path,
            )
        else:
            event_value = events_processors.video(
                asset_path=asset_path,
                tensor=data,
                fps=fps,
                content_type=content_type,
                asset_rel_path=asset_rel_path,
            )

        if event_value == UNKNOWN:
            return

        logged_event = LoggedEventSpec(
            name=name,
            kind=V1ArtifactKind.VIDEO,
            event=V1Event.make(timestamp=timestamp,
                               step=step,
                               video=event_value),
        )
        self._event_logger.add_event(logged_event)