Shortcuts

mmedit.engine.hooks.visualization_hook

Module Contents

Classes

BasicVisualizationHook

Basic hook that invoke visualizers during validation and test.

GenVisualizationHook

Generation Visualization Hook. Used to visual output samples in

class mmedit.engine.hooks.visualization_hook.BasicVisualizationHook(interval: dict = {}, on_train=False, on_val=True, on_test=True)[源代码]

Bases: mmengine.hooks.Hook

Basic hook that invoke visualizers during validation and test.

参数
  • interval (int | dict) – Visualization interval. Default: {}.

  • on_train (bool) – Whether to call hook during train. Default to False.

  • on_val (bool) – Whether to call hook during validation. Default to True.

  • on_test (bool) – Whether to call hook during test. Default to True.

priority = 'NORMAL'[源代码]
_after_iter(runner, batch_idx: int, data_batch: Optional[Sequence[dict]], outputs: Optional[Sequence[mmengine.structures.BaseDataElement]], mode=None) None[源代码]

Show or Write the predicted results.

参数
  • runner (Runner) – The runner of the training process.

  • batch_idx (int) – The index of the current batch in the test loop.

  • data_batch (Sequence[dict], optional) – Data from dataloader. Defaults to None.

  • outputs (Sequence[BaseDataElement], optional) – Outputs from model. Defaults to None.

class mmedit.engine.hooks.visualization_hook.GenVisualizationHook(interval: int = 1000, vis_kwargs_list: Tuple[List[dict], dict] = None, fixed_input: bool = True, n_samples: Optional[int] = 64, n_row: Optional[int] = 8, message_hub_vis_kwargs: Optional[Tuple[str, dict, List[str], List[Dict]]] = None, save_at_test: bool = True, max_save_at_test: int = 100, test_vis_keys: Optional[Union[str, List[str]]] = None, show: bool = False, wait_time: float = 0)[源代码]

Bases: mmengine.hooks.Hook

Generation Visualization Hook. Used to visual output samples in training, validation and testing. In this hook, we use a list called sample_kwargs_list to control how to generate samples and how to visualize them. Each element in sample_kwargs_list, called sample_kwargs, may contains the following keywords:

  • Required key words:
    • ‘type’: Value must be string. Denotes what kind of sampler is used to

      generate image. Refers to get_sampler().

  • Optional key words (If not passed, will use the default value):
    • ‘n_rows’: Value must be int. The number of images in one row.

    • ‘num_samples’: Value must be int. The number of samples to visualize.

    • ‘vis_mode’: Value must be string. How to visualize the generated

      samples (e.g. image, gif).

    • ‘fixed_input’: Value must be bool. Whether use the fixed input

      during the loop.

    • ‘draw_gt’: Value must be bool. Whether save the real images.

    • ‘target_keys’: Value must be string or list of string. The keys of

      the target image to visualize.

    • ‘name’: Value must be string. If not passed, will use

      sample_kwargs[‘type’] as default.

For convenience, we also define a group of alias of samplers’ type for models supported in MMEditing. Refers to :attr:self.SAMPLER_TYPE_MAPPING.

示例

>>> # for GAN models
>>> custom_hooks = [
>>>     dict(
>>>         type='GenVisualizationHook',
>>>         interval=1000,
>>>         fixed_input=True,
>>>         vis_kwargs_list=dict(type='GAN', name='fake_img'))]
>>> # for Translation models
>>> custom_hooks = [
>>>     dict(
>>>         type='GenVisualizationHook',
>>>         interval=10,
>>>         fixed_input=False,
>>>         vis_kwargs_list=[dict(type='Translation',
>>>                                  name='translation_train',
>>>                                  n_samples=6, draw_gt=True,
>>>                                  n_rows=3),
>>>                             dict(type='TranslationVal',
>>>                                  name='translation_val',
>>>                                  n_samples=16, draw_gt=True,
>>>                                  n_rows=4)])]

# NOTE: user-defined vis_kwargs > vis_kwargs_mapping > hook init args

参数
  • interval (int) – Visualization interval. Default: 1000.

  • sampler_kwargs_list (Tuple[List[dict], dict]) – The list of sampling behavior to generate images.

  • fixed_input (bool) – The default action of whether use fixed input to generate samples during the loop. Defaults to True.

  • n_samples (Optional[int]) – The default value of number of samples to visualize. Defaults to 64.

  • n_row (Optional[int]) – The default value of number of images in each row in the visualization results. Defaults to 8.

  • (Optional[Tuple[str (message_hub_vis_kwargs) – List[Dict]]]): Key arguments visualize images in message hub. Defaults to None.

  • dict – List[Dict]]]): Key arguments visualize images in message hub. Defaults to None.

  • List[str] – List[Dict]]]): Key arguments visualize images in message hub. Defaults to None.

:paramList[Dict]]]): Key arguments visualize images in message hub.

Defaults to None.

参数
  • save_at_test (bool) – Whether save images during test. Defaults to True.

  • max_save_at_test (int) – Maximum number of samples saved at test time. If None is passed, all samples will be saved. Defaults to 100.

  • show (bool) – Whether to display the drawn image. Default to False.

  • wait_time (float) – The interval of show (s). Defaults to 0.

priority = 'NORMAL'[源代码]
VIS_KWARGS_MAPPING[源代码]
after_val_iter(runner: mmengine.runner.Runner, batch_idx: int, data_batch: dict, outputs) None[源代码]

GenVisualizationHook do not support visualize during validation.

参数
  • runner (Runner) – The runner of the training process.

  • batch_idx (int) – The index of the current batch in the test loop.

  • data_batch (Sequence[dict], optional) – Data from dataloader. Defaults to None.

  • outputs – outputs of the generation model

after_test_iter(runner: mmengine.runner.Runner, batch_idx: int, data_batch: dict, outputs)[源代码]

Visualize samples after test iteraiton.

参数
  • runner (Runner) – The runner of the training process.

  • batch_idx (int) – The index of the current batch in the test loop.

  • data_batch (dict, optional) – Data from dataloader. Defaults to None.

  • outputs – outputs of the generation model Defaults to None.

after_train_iter(runner: mmengine.runner.Runner, batch_idx: int, data_batch: dict = None, outputs: Optional[dict] = None) None[源代码]

Visualize samples after train iteration.

参数
  • runner (Runner) – The runner of the training process.

  • batch_idx (int) – The index of the current batch in the train loop.

  • data_batch (dict) – Data from dataloader. Defaults to None.

  • outputs (dict, optional) – Outputs from model. Defaults to None.

vis_sample(runner: mmengine.runner.Runner, batch_idx: int, data_batch: dict, outputs: Optional[dict] = None) None[源代码]

Visualize samples.

参数
  • runner (Runner) – The runner conatians model to visualize.

  • batch_idx (int) – The index of the current batch in loop.

  • data_batch (dict) – Data from dataloader. Defaults to None.

  • outputs (dict, optional) – Outputs from model. Defaults to None.

vis_from_message_hub(batch_idx: int, color_order: str, target_mean: Sequence[Union[float, int]], target_std: Sequence[Union[float, int]])[源代码]

Visualize samples from message hub.

参数
  • batch_idx (int) – The index of the current batch in the test loop.

  • color_order (str) – The color order of generated images.

  • target_mean (Sequence[Union[float, int]]) – The original mean of the image tensor before preprocessing. Image will be re-shifted to target_mean before visualizing.

  • target_std (Sequence[Union[float, int]]) – The original std of the image tensor before preprocessing. Image will be re-scaled to target_std before visualizing.

Read the Docs v: latest
Versions
master
latest
stable
zyh-doc-notfound-extend
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.