mindspore.dataset.config.set_debug_mode

View Source On Gitee
mindspore.dataset.config.set_debug_mode(debug_mode_flag: bool, debug_hook_list: list = None)

Set the debug_mode flag of the dataset pipeline. When enabled, the dataset pipeline is run synchronously and sequentially with a single thread.

Note

When debug_mode is enabled,

  • If random seed has not been set, will internally set the seed to 1. So that debug mode execution of the dataset pipeline can produce deterministic results.

  • The following configuration settings are ignored:

    • auto_offload (False is used.)

    • enable_autotune (False is used.)

    • error_samples_mode (ErrorSamplesMode.RETURN is used.)

    • num_parallel_workers (Value 1 is used.)

  • The offload parameter in map operation will be ignored.

  • The python_multiprocessing parameter in GeneratorDataset, map/batch operation will be ignored.

  • The cache parameter in Dataset loading API will be ignored.

Parameters
  • debug_mode_flag (bool) – Whether dataset pipeline debug mode is enabled, which forces the pipeline to run synchronously and sequentially.

  • debug_hook_list (list[DebugHook]) – a list of debug hook objects to be inserted before and after each transform operation in map operation. Default: None, which means to use basic print hook, which prints shape/size/type of each input/output data of each transformation.

Raises
  • TypeError – If debug_mode_flag is not a boolean data type.

  • TypeError – If debug_hook_list is not a list type.

  • TypeError – If any item in debug_hook_list is not DebugHook type.

Examples

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.vision as vision
>>> import mindspore.dataset.debug as debug
>>>
>>> # 1. Enable dataset pipeline debug mode and use default debug hook.
>>> # Print shape and type of input/output data of each transform op in map operator.
>>> ds.config.set_debug_mode(True)
>>>
>>> # 2. Enable dataset pipeline debug mode and use pre-defined debug hook provided by MindData.
>>> ds.config.set_debug_mode(True, debug_hook_list=[debug.PrintDataHook()])
>>>
>>> # 3. Enable dataset pipeline debug mode and use user-defined debug hook. It must define a
>>> # class inherited from DebugHook.
>>> class CustomizedHook(debug.DebugHook):
...     def __init__(self):
...         super().__init__()
...
...     def compute(self, *args):
...         # Add your debugging code here.
...         return args
>>>
>>> ds.config.set_debug_mode(True, debug_hook_list=[CustomizedHook()])
>>>
>>> # 4. Enable dataset pipeline debug mode and use user-defined debug hook and insert by users manually.
>>> ds.config.set_debug_mode(True)
>>> dataset = ds.ImageFolderDataset(dataset_dir="/path/to/image_folder_dataset_directory")
>>>
>>> # The debug hook is added after Decode operation.
>>> dataset = dataset.map([vision.Decode(), CustomizedHook(), vision.CenterCrop(100)])