MCPcopy Create free account
hub / github.com/ViTAE-Transformer/MTP / forward

Method forward

Multi-Task_Pretrain/preprocessing.py:145–187  ·  view source on GitHub ↗

Perform normalization、padding and bgr2rgb conversion based on ``BaseDataPreprocessor``. Args: data (dict): Data sampled from dataloader. training (bool): Whether to enable training time augmentation. Returns: dict: Data in the same format

(self, data: dict, training: bool = False)

Source from the content-addressed store, hash-verified

143 self.boxtype2tensor = boxtype2tensor
144
145 def forward(self, data: dict, training: bool = False) -> dict:
146 """Perform normalization、padding and bgr2rgb conversion based on
147 ``BaseDataPreprocessor``.
148
149 Args:
150 data (dict): Data sampled from dataloader.
151 training (bool): Whether to enable training time augmentation.
152
153 Returns:
154 dict: Data in the same format as the model input.
155 """
156 batch_pad_shape = self._get_pad_shape(data)
157 data = super().forward(data=data, training=training)
158 inputs, data_samples = data['inputs'], data['data_samples']
159
160 if data_samples is not None:
161 # NOTE the batched image size information may be useful, e.g.
162 # in DETR, this is needed for the construction of masks, which is
163 # then used for the transformer_head.
164 batch_input_shape = tuple(inputs[0].size()[-2:])
165 for data_sample, pad_shape in zip(data_samples, batch_pad_shape):
166 data_sample.set_metainfo({
167 'batch_input_shape': batch_input_shape,
168 'pad_shape': pad_shape
169 })
170
171 if self.boxtype2tensor:
172 samplelist_boxtype2tensor(data_samples)
173 # for rotated detection
174 #r_samplelist_boxtype2tensor(data_samples)
175
176
177 if self.pad_mask and training:
178 self.pad_gt_masks(data_samples)
179
180 if self.pad_seg and training:
181 self.pad_gt_sem_seg(data_samples)
182
183 if training and self.batch_augments is not None:
184 for batch_aug in self.batch_augments:
185 inputs, data_samples = batch_aug(inputs, data_samples)
186
187 return {'inputs': inputs, 'data_samples': data_samples}
188
189 def _get_pad_shape(self, data: dict) -> List[tuple]:
190 """Get the pad_shape of each image based on data and

Callers

nothing calls this directly

Calls 4

_get_pad_shapeMethod · 0.95
pad_gt_masksMethod · 0.95
pad_gt_sem_segMethod · 0.95

Tested by

no test coverage detected