MCPcopy Create free account
hub / github.com/open-mmlab/mmengine / ImgDataPreprocessor

Class ImgDataPreprocessor

mmengine/model/base_model/data_preprocessor.py:154–308  ·  view source on GitHub ↗

Image pre-processor for normalization and bgr to rgb conversion. Accepts the data sampled by the dataloader, and preprocesses it into the format of the model input. ``ImgDataPreprocessor`` provides the basic data pre-processing as follows - Collates and moves data to the target dev

Source from the content-addressed store, hash-verified

152
153@MODELS.register_module()
154class ImgDataPreprocessor(BaseDataPreprocessor):
155 """Image pre-processor for normalization and bgr to rgb conversion.
156
157 Accepts the data sampled by the dataloader, and preprocesses it into the
158 format of the model input. ``ImgDataPreprocessor`` provides the
159 basic data pre-processing as follows
160
161 - Collates and moves data to the target device.
162 - Converts inputs from bgr to rgb if the shape of input is (3, H, W).
163 - Normalizes image with defined std and mean.
164 - Pads inputs to the maximum size of current batch with defined
165 ``pad_value``. The padding size can be divisible by a defined
166 ``pad_size_divisor``
167 - Stack inputs to batch_inputs.
168
169 For ``ImgDataPreprocessor``, the dimension of the single inputs must be
170 (3, H, W).
171
172 Note:
173 ``ImgDataPreprocessor`` and its subclass is built in the
174 constructor of :class:`BaseDataset`.
175
176 Args:
177 mean (Sequence[float or int], optional): The pixel mean of image
178 channels. If ``bgr_to_rgb=True`` it means the mean value of R,
179 G, B channels. If the length of `mean` is 1, it means all
180 channels have the same mean value, or the input is a gray image.
181 If it is not specified, images will not be normalized. Defaults
182 None.
183 std (Sequence[float or int], optional): The pixel standard deviation of
184 image channels. If ``bgr_to_rgb=True`` it means the standard
185 deviation of R, G, B channels. If the length of `std` is 1,
186 it means all channels have the same standard deviation, or the
187 input is a gray image. If it is not specified, images will
188 not be normalized. Defaults None.
189 pad_size_divisor (int): The size of padded image should be
190 divisible by ``pad_size_divisor``. Defaults to 1.
191 pad_value (float or int): The padded pixel value. Defaults to 0.
192 bgr_to_rgb (bool): whether to convert image from BGR to RGB.
193 Defaults to False.
194 rgb_to_bgr (bool): whether to convert image from RGB to RGB.
195 Defaults to False.
196 non_blocking (bool): Whether block current process
197 when transferring data to device.
198 New in version v0.3.0.
199
200 Note:
201 if images do not need to be normalized, `std` and `mean` should be
202 both set to None, otherwise both of them should be set to a tuple of
203 corresponding values.
204 """
205
206 def __init__(self,
207 mean: Optional[Sequence[Union[float, int]]] = None,
208 std: Optional[Sequence[Union[float, int]]] = None,
209 pad_size_divisor: int = 1,
210 pad_value: Union[float, int] = 0,
211 bgr_to_rgb: bool = False,

Callers 2

test_initMethod · 0.90
test_forwardMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_initMethod · 0.72
test_forwardMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…