Shortcuts

TransformBroadcaster

class mmcv.transforms.TransformBroadcaster(transforms: List[Union[Dict, Callable[[Dict], Dict]]], mapping: Optional[Dict] = None, remapping: Optional[Dict] = None, auto_remap: Optional[bool] = None, allow_nonexist_keys: bool = False, share_random_params: bool = False)[源代码]

A transform wrapper to apply the wrapped transforms to multiple data items. For example, apply Resize to multiple images.

参数
  • transforms (list[dict | callable]) – Sequence of transform object or config dict to be wrapped.

  • mapping (dict) – A dict that defines the input key mapping. Note that to apply the transforms to multiple data items, the outer keys of the target items should be remapped as a list with the standard inner key (The key required by the wrapped transform). See the following example and the document of mmcv.transforms.wrappers.KeyMapper for details.

  • remapping (dict) – A dict that defines the output key mapping. The keys and values have the same meanings and rules as in the mapping. Default: None.

  • auto_remap (bool, optional) – If True, an inverse of the mapping will be used as the remapping. If auto_remap is not given, it will be automatically set True if ‘remapping’ is not given, and vice versa. Default: None.

  • allow_nonexist_keys (bool) – If False, the outer keys in the mapping must exist in the input data, or an exception will be raised. Default: False.

  • share_random_params (bool) – If True, the random transform (e.g., RandomFlip) will be conducted in a deterministic way and have the same behavior on all data items. For example, to randomly flip either both input image and ground-truth image, or none. Default: False.

注解

To apply the transforms to each elements of a list or tuple, instead of separating data items, you can map the outer key of the target sequence to the standard inner key. See example 2. example.

实际案例

>>> # Example 1: Broadcast to enumerated keys, each contains a single
>>> # data element
>>> pipeline = [
>>>     dict(type='LoadImageFromFile', key='lq'),  # low-quality img
>>>     dict(type='LoadImageFromFile', key='gt'),  # ground-truth img
>>>     # TransformBroadcaster maps multiple outer fields to standard
>>>     # the inner field and process them with wrapped transforms
>>>     # respectively
>>>     dict(type='TransformBroadcaster',
>>>         # case 1: from multiple outer fields
>>>         mapping={'img': ['lq', 'gt']},
>>>         auto_remap=True,
>>>         # share_random_param=True means using identical random
>>>         # parameters in every processing
>>>         share_random_param=True,
>>>         transforms=[
>>>             dict(type='Crop', crop_size=(384, 384)),
>>>             dict(type='Normalize'),
>>>         ])
>>> ]
>>> # Example 2: Broadcast to keys that contains data sequences
>>> pipeline = [
>>>     dict(type='LoadImageFromFile', key='lq'),  # low-quality img
>>>     dict(type='LoadImageFromFile', key='gt'),  # ground-truth img
>>>     # TransformBroadcaster maps multiple outer fields to standard
>>>     # the inner field and process them with wrapped transforms
>>>     # respectively
>>>     dict(type='TransformBroadcaster',
>>>         # case 2: from one outer field that contains multiple
>>>         # data elements (e.g. a list)
>>>         # mapping={'img': 'images'},
>>>         auto_remap=True,
>>>         share_random_param=True,
>>>         transforms=[
>>>             dict(type='Crop', crop_size=(384, 384)),
>>>             dict(type='Normalize'),
>>>         ])
>>> ]
>>> Example 3: Set ignored keys in broadcasting
>>> pipeline = [
>>>        dict(type='TransformBroadcaster',
>>>            # Broadcast the wrapped transforms to multiple images
>>>            # 'lq' and 'gt, but only update 'img_shape' once
>>>            mapping={
>>>                'img': ['lq', 'gt'],
>>>                'img_shape': ['img_shape', ...],
>>>             },
>>>            auto_remap=True,
>>>            share_random_params=True,
>>>            transforms=[
>>>                # `RandomCrop` will modify the field "img",
>>>                # and optionally update "img_shape" if it exists
>>>                dict(type='RandomCrop'),
>>>            ])
>>>    ]
scatter_sequence(data: Dict)List[Dict][源代码]

Scatter the broadcasting targets to a list of inputs of the wrapped transforms.

transform(results: Dict)[源代码]

Broadcast wrapped transforms to multiple targets.

Read the Docs v: stable
Versions
latest
stable
2.x
v2.0.1
v2.0.0
1.x
v1.7.1
v1.7.0
v1.6.2
v1.6.1
v1.6.0
v1.5.3
v1.5.2_a
v1.5.1
v1.5.0
v1.4.8
v1.4.7
v1.4.6
v1.4.5
v1.4.4
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.3.18
v1.3.17
v1.3.16
v1.3.15
v1.3.14
v1.3.13
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.