Shortcuts

mmagic.visualization.vis_backend

Module Contents

Classes

VisBackend

MMagic visualization backend class. It can write image, config, scalars,

TensorboardVisBackend

Tensorboard visualization backend class.

PaviVisBackend

Visualization backend for Pavi.

WandbVisBackend

Wandb visualization backend for MMagic.

class mmagic.visualization.vis_backend.VisBackend(save_dir: str, img_save_dir: str = 'vis_image', config_save_file: str = 'config.py', scalar_save_file: str = 'scalars.json', ceph_path: Optional[str] = None, delete_local_image: bool = True)[源代码]

Bases: mmengine.visualization.BaseVisBackend

MMagic visualization backend class. It can write image, config, scalars, etc. to the local hard disk and ceph path. You can get the drawing backend through the experiment property for custom drawing.

实际案例

>>> from mmagic.visualization import VisBackend
>>> import numpy as np
>>> vis_backend = VisBackend(save_dir='temp_dir',
>>>                          ceph_path='s3://temp-bucket')
>>> img = np.random.randint(0, 256, size=(10, 10, 3))
>>> vis_backend.add_image('img', img)
>>> vis_backend.add_scalar('mAP', 0.6)
>>> vis_backend.add_scalars({'loss': [1, 2, 3], 'acc': 0.8})
>>> cfg = Config(dict(a=1, b=dict(b1=[0, 1])))
>>> vis_backend.add_config(cfg)
参数
  • save_dir (str) – The root directory to save the files produced by the visualizer.

  • img_save_dir (str) – The directory to save images. Default to ‘vis_image’.

  • config_save_file (str) – The file name to save config. Default to ‘config.py’.

  • scalar_save_file (str) – The file name to save scalar values. Default to ‘scalars.json’.

  • ceph_path (Optional[str]) – The remote path of Ceph cloud storage. Defaults to None.

  • delete_local (bool) – Whether delete local after uploading to ceph or not. If ceph_path is None, this will be ignored. Defaults to True.

property experiment: VisBackend[源代码]

Return the experiment object associated with this visualization backend.

_init_env()[源代码]

Setup env for VisBackend.

add_config(config: mmengine.config.Config, **kwargs) None[源代码]

Record the config to disk.

参数

config (Config) – The Config object

add_image(name: str, image: numpy.array, step: int = 0, **kwargs) None[源代码]

Record the image to disk.

参数
  • name (str) – The image identifier.

  • image (np.ndarray) – The image to be saved. The format should be RGB. Default to None.

  • step (int) – Global step value to record. Default to 0.

add_scalar(name: str, value: Union[int, float, torch.Tensor, numpy.ndarray], step: int = 0, **kwargs) None[源代码]

Record the scalar data to disk.

参数
  • name (str) – The scalar identifier.

  • value (int, float, torch.Tensor, np.ndarray) – Value to save.

  • step (int) – Global step value to record. Default to 0.

add_scalars(scalar_dict: dict, step: int = 0, file_path: Optional[str] = None, **kwargs) None[源代码]

Record the scalars to disk.

The scalar dict will be written to the default and specified files if file_path is specified.

参数
  • scalar_dict (dict) – Key-value pair storing the tag and corresponding values. The value must be dumped into json format.

  • step (int) – Global step value to record. Default to 0.

  • file_path (str, optional) – The scalar’s data will be saved to the file_path file at the same time if the file_path parameter is specified. Default to None.

_dump(value_dict: dict, file_path: str, file_format: str) None[源代码]

dump dict to file.

参数
  • value_dict (dict) – The dict data to saved.

  • file_path (str) – The file path to save data.

  • file_format (str) – The file format to save data.

_upload(path: str, delete_local=False) None[源代码]

Upload file at path to remote.

参数

path (str) – Path of file to upload.

class mmagic.visualization.vis_backend.TensorboardVisBackend(save_dir: str)[源代码]

Bases: mmengine.visualization.TensorboardVisBackend

Tensorboard visualization backend class.

It can write images, config, scalars, etc. to a tensorboard file.

实际案例

>>> from mmengine.visualization import TensorboardVisBackend
>>> import numpy as np
>>> vis_backend = TensorboardVisBackend(save_dir='temp_dir')
>>> img = np.random.randint(0, 256, size=(10, 10, 3))
>>> vis_backend.add_image('img', img)
>>> vis_backend.add_scaler('mAP', 0.6)
>>> vis_backend.add_scalars({'loss': 0.1,'acc':0.8})
>>> cfg = Config(dict(a=1, b=dict(b1=[0, 1])))
>>> vis_backend.add_config(cfg)
参数

save_dir (str) – The root directory to save the files produced by the backend.

add_image(name: str, image: numpy.array, step: int = 0, **kwargs)[源代码]

Record the image to Tensorboard. Additional support upload gif files.

参数
  • name (str) – The image identifier.

  • image (np.ndarray) – The image to be saved. The format should be RGB.

  • step (int) – Useless parameter. Wandb does not need this parameter. Default to 0.

class mmagic.visualization.vis_backend.PaviVisBackend(save_dir: str, exp_name: Optional[str] = None, labels: Optional[str] = None, project: Optional[str] = None, model: Optional[str] = None, description: Optional[str] = None)[源代码]

Bases: mmengine.visualization.BaseVisBackend

Visualization backend for Pavi.

property experiment: VisBackend[源代码]

Return the experiment object associated with this visualization backend.

_init_env()[源代码]

Init save dir.

add_image(name: str, image: numpy.array, step: int = 0, **kwargs) None[源代码]

Record the image to Pavi.

参数
  • name (str) – The image identifier.

  • image (np.ndarray) – The image to be saved. The format should be RGB. Default to None.

  • step (int) – Global step value to record. Default to 0.

add_scalar(name: str, value: Union[int, float, torch.Tensor, numpy.ndarray], step: int = 0, **kwargs) None[源代码]

Record the scalar data to Pavi.

参数
  • name (str) – The scalar identifier.

  • value (int, float, torch.Tensor, np.ndarray) – Value to save.

  • step (int) – Global step value to record. Default to 0.

add_scalars(scalar_dict: dict, step: int = 0, file_path: Optional[str] = None, **kwargs) None[源代码]

Record the scalars to Pavi.

The scalar dict will be written to the default and specified files if file_path is specified.

参数
  • scalar_dict (dict) – Key-value pair storing the tag and corresponding values. The value must be dumped into json format.

  • step (int) – Global step value to record. Default to 0.

  • file_path (str, optional) – The scalar’s data will be saved to the file_path file at the same time if the file_path parameter is specified. Default to None.

class mmagic.visualization.vis_backend.WandbVisBackend(save_dir: str, init_kwargs: Optional[dict] = None, define_metric_cfg: Union[dict, list, None] = None, commit: Optional[bool] = True, log_code_name: Optional[str] = None, watch_kwargs: Optional[dict] = None)[源代码]

Bases: mmengine.visualization.WandbVisBackend

Wandb visualization backend for MMagic.

_init_env()[源代码]

Setup env for wandb.

add_image(name: str, image: numpy.array, step: int = 0, **kwargs)[源代码]

Record the image to wandb. Additional support upload gif files.

参数
  • name (str) – The image identifier.

  • image (np.ndarray) – The image to be saved. The format should be RGB.

  • step (int) – Useless parameter. Wandb does not need this parameter. Default to 0.

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.