In MMCV, data preparation is decoupled from dataset construction. Data transforms are callable classes that accept a configuration during instantiation and process a data dictionary.
Key Conventions:
- Input/Output: Every transform accepts a
dict as input and returns a dict as output. - Field Interaction: Transforms read specific fields (e.g.,
Resize reads img) and may add or update other fields. - Dimension Ordering:
- For initialization parameters (e.g.,
Resize, Pad), the image size order is (width, height). - For returned dictionary fields (e.g.,
img_shape, ori_shape, pad_shape), the order is (height, width).
>>> import numpy as np
>>> from mmcv.transforms import Resize
>>>
>>> transform = Resize(scale=(224, 224))
>>> data_dict = {'img': np.random.rand(256, 256, 3)}
>>> data_dict = transform(data_dict)
>>> print(data_dict['img'].shape)
(224, 224, 3)