Пример #1
0
    def image(self, images, name=None, ch_axis=1, row=0, mode=None,
              batched=True, subdir=''):
        """Summarize images to visualize.

        Args:
            images (:class:`numpy.ndarray` or :class:`cupy.ndarray` or \
                :class:`chainer.Variable`): batch of images. If Number of
                dimension is 3 (or 2 when set `batched=False`), the pixels
                assume as black and white image.
            name (str): name of image. set as column name. when not setting,
                assigned ``'image'`` + sequential number.
            ch_axis (int): index number of channel dimension. set 1 by default.
                if the images don't have channel axis, this parameter is
                ignored.
            row (int): row size to visualize batched images. when set 0,
                show on unstuck. if images set only one image, the row size
                will be ignored.
            mode (str): if the images are not RGB or RGBA space, set their
                color space code. ChainerUI supports 'HSV'.
            batched (bool): if the image is not batched, set ``False``.
            subdir (str): sub-directory path of output.
        """
        from chainerui.report.image_report import check_available
        if not check_available():
            return
        from chainerui.report.image_report import report as _image

        col_name = self.get_col_name(name, 'image')
        out_dir, rel_out_dir = self.get_subdir(subdir)
        filename, _ = _image(
            images, out_dir, col_name, ch_axis, row, mode, batched)
        self.images[col_name] = os.path.join(rel_out_dir, filename)

        self.count += 1
Пример #2
0
def audio(audio, sample_rate, name=None, out=None, subdir='', timeout=5,
          **kwargs):
    """Summarize audio files to listen on a browser.

    An sampled array is converted as WAV audio file, saved to output directory,
    and reported to the ChainerUI server. The audio file is saved every called
    this function. The audio file will be listened on `assets` endpoint
    vertically. If need to aggregate audio files in row, use
    :func:`~chainerui.summary.reporter`.

    Example of how to set arguments::

       >>> from chainerui import summary
       >>> summary.set_out('/path/to/output')
       >>> rate = 44100
       >>>
       >>> summary.audio(sampled_array, rate, name='test')
       >>> # sampled_array can be listened on a browser.

    Add description about the audio file::

       >>> summary.image(
       >>>     sampled_array, rate, name='test', epoch=1, iteration=100)
       >>> # 'epoch' and 'iteration' column will be shown.

    Args:
        audio (:class:`numpy.ndarray` or :class:`cupy.ndarray` or \
            :class:`chainer.Variable`): sampled wave array.
        sample_rate (int): sampling rate.
        name (str): name of image. set as column name. when not setting,
            assigned ``'audio'``.
        out (str): directory path of output.
        subdir (str): sub-directory path of output.
        **kwargs (dict): key-value pair to show as description. regardless of
            empty or not, timestamp on created the image is added.
    """

    from chainerui.report.audio_report import check_available
    if not check_available():
        return
    from chainerui.report.audio_report import report as _audio

    out_root = _chainerui_asset_observer.get_outpath(out)
    out_path = os.path.join(out_root, subdir)
    if not os.path.isdir(out_path):
        os.makedirs(out_path)
    col_name = name
    if col_name is None:
        col_name = 'audio'
    filename, created_at = _audio(audio, sample_rate, out_path, col_name)

    value = kwargs
    value['timestamp'] = created_at.isoformat()
    value['audios'] = {col_name: os.path.join(subdir, filename)}
    _chainerui_asset_observer.add(value)
    _chainerui_asset_observer.save(out_root, timeout)
Пример #3
0
    def audio(self, audio, sample_rate, name=None, subdir=''):
        """Summarize audio to listen on web browser.

        Args:
            audio (:class:`numpy.ndarray` or :class:`cupy.ndarray` or \
                :class:`chainer.Variable`): sampled wave array.
            sample_rate (int): sampling rate.
            name (str): name of image. set as column name. when not setting,
                assigned ``'audio'`` + sequential number.
            subdir (str): sub-directory path of output.
        """

        from chainerui.report.audio_report import check_available
        if not check_available():
            return
        from chainerui.report.audio_report import report as _audio

        col_name = self.get_col_name(name, 'audio')
        out_dir, rel_out_dir = self.get_subdir(subdir)
        filename, _ = _audio(audio, sample_rate, out_dir, col_name)
        self.audios[col_name] = os.path.join(rel_out_dir, filename)

        self.count += 1
Пример #4
0
def image(images,
          name=None,
          ch_axis=1,
          row=0,
          mode=None,
          batched=True,
          out=None,
          subdir='',
          timeout=5,
          **kwargs):
    """Summarize images to visualize.

    Array of images are converted as image format (PNG format on default),
    saved to output directory, and reported to the ChainerUI server.
    The images are saved every called this function. The images will be shown
    on `assets` endpoint vertically. If need to aggregate images in a row, use
    :func:`~chainerui.summary.reporter`.

    Examples of how to set arguments:

       >>> from chainerui import summary
       >>> summary.set_out('path/to/log')  # same as 'log' file directory
       >>>
       >>> x = np.zeros((10, 3, 5, 5))  # = [Batchsize, Channel, Height, Width]
       >>> summary.image(x, name='test')  # images are tiled as 1x10
       >>> summary.image(x, name='test', row=2)  # images are tiled as 2x5
       >>>
       >>> x = np.zeros((3, 5, 5))  # = [C, H, W]
       >>> # need to set as a non-batched image and channel axis explicitly
       >>> summary.image(x, name='test', ch_axis=0, batched=False)
       >>>
       >>> x = np.zeros((10, 5, 5, 3))  # = [B, H, W, C]
       >>> # need to set channel axis explicitly
       >>> summary.image(x, name='test', ch_axis=-1, row=2)
       >>>
       >>> x = np.zeros((5, 5, 3))  # = [H, W, C]
       >>> # need to set as a non-batched image
       >>> summary.image(x, name='test', ch_axis=-1, batched=False)
       >>>
       >>> x = np.zeros((10, 5, 5))  # = [B, H, W], grayscale images
       >>> summary.image(x, name='test')  # image are tiled as 1x10
       >>> summary.image(x, name='test', row=2)  # image are tiled as 2x5
       >>>
       >>> x = np.zeros((5, 5)) # = [H, W], a grayscale image
       >>> # need to set as a non-bathed image
       >>> summary.image(x, name='test', batched=False)

    Add description about the image::

       >>> summary.image(x, name='test', epoch=1, iteration=100)
       >>> # 'epoch' and 'iteration' column will be shown.

    Args:
        images (:class:`numpy.ndarray` or :class:`cupy.ndarray` or \
            :class:`chainer.Variable`): batch of images. If Number of dimension
            is 3 (or 2 when set `batched=False`), the pixels assume as
            black and white image.
        name (str): name of image. set as column name. when not setting,
            assigned ``'image'``.
        ch_axis (int): index number of channel dimension. set 1 by default.
            if the images don't have channel axis, this parameter is ignored.
        row (int): row size to visualize batched images. when set 0,
            show on unstuck. if images set only one image, the row size
            will be ignored.
        mode (str): if the images are not RGB or RGBA space, set their
            color space code. ChainerUI supports 'HSV'.
        batched (bool): if the image is not batched, set ``False``.
        out (str): directory path of output.
        subdir (str): sub-directory path of output.
        **kwargs (dict): key-value pair to show as description. regardless of
            empty or not, timestamp on created the image is added.
    """

    from chainerui.report.image_report import check_available
    if not check_available():
        return
    from chainerui.report.image_report import report as _image

    out_root = _chainerui_asset_observer.get_outpath(out)
    out_path = os.path.join(out_root, subdir)
    if not os.path.isdir(out_path):
        os.makedirs(out_path)
    col_name = name
    if col_name is None:
        col_name = 'image'
    filename, created_at = _image(images, out_path, col_name, ch_axis, row,
                                  mode, batched)

    value = kwargs
    value['timestamp'] = created_at.isoformat()
    value['images'] = {col_name: os.path.join(subdir, filename)}
    _chainerui_asset_observer.add(value)
    _chainerui_asset_observer.save(out_root, timeout)
Пример #5
0
 def check_available():
     with warnings.catch_warnings(record=True) as w:
         assert not image_report.check_available()
         assert len(w) == 1