MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / DefaultFormatBundle

Class DefaultFormatBundle

detrsmpl/data/datasets/pipelines/formatting.py:184–290  ·  view source on GitHub ↗

Default formatting bundle. It simplifies the pipeline of formatting common fields, including "img", "proposals", "gt_bboxes", "gt_labels", "gt_masks" and "gt_semantic_seg". These fields are formatted as follows. - img: (1)transpose, (2)to tensor, (3)to DataContainer (stack=True)

Source from the content-addressed store, hash-verified

182
183@PIPELINES.register_module()
184class DefaultFormatBundle:
185 """Default formatting bundle.
186
187 It simplifies the pipeline of formatting common fields, including "img",
188 "proposals", "gt_bboxes", "gt_labels", "gt_masks" and "gt_semantic_seg".
189 These fields are formatted as follows.
190
191 - img: (1)transpose, (2)to tensor, (3)to DataContainer (stack=True)
192 - proposals: (1)to tensor, (2)to DataContainer
193 - gt_bboxes: (1)to tensor, (2)to DataContainer
194 - gt_bboxes_ignore: (1)to tensor, (2)to DataContainer
195 - gt_labels: (1)to tensor, (2)to DataContainer
196 - gt_masks: (1)to tensor, (2)to DataContainer (cpu_only=True)
197 - gt_semantic_seg: (1)unsqueeze dim-0 (2)to tensor, \
198 (3)to DataContainer (stack=True)
199
200 Args:
201 img_to_float (bool): Whether to force the image to be converted to
202 float type. Default: True.
203 pad_val (dict): A dict for padding value in batch collating,
204 the default value is `dict(img=0, masks=0, seg=255)`.
205 Without this argument, the padding value of "gt_semantic_seg"
206 will be set to 0 by default, which should be 255.
207 """
208 def __init__(self,
209 img_to_float=True,
210 pad_val=dict(img=0, masks=0, seg=255)):
211 self.img_to_float = img_to_float
212 self.pad_val = pad_val
213
214 def __call__(self, results):
215 """Call function to transform and format common fields in results.
216
217 Args:
218 results (dict): Result dict contains the data to convert.
219
220 Returns:
221 dict: The result dict contains the data that is formatted with \
222 default bundle.
223 """
224 data_keys = [
225 'center', 'scale', 'rotation', 'smpl_body_pose',
226 'smpl_global_orient', 'smpl_betas', 'smpl_transl', 'area',
227 'bbox_xywh', 'has_smpl', 'keypoints2d_ori', 'keypoints3d_ori',
228 'keypoints2d_smpl', 'keypoints3d_smpl', 'has_keypoints2d_ori',
229 'has_keypoints3d_ori', 'has_keypoints2d_smpl',
230 'has_keypoints3d_smpl'
231 ]
232 if 'img' in results:
233 img = results['img']
234 if self.img_to_float is True and img.dtype == np.uint8:
235 # Normally, image is of uint8 type without normalization.
236 # At this time, it needs to be forced to be converted to
237 # flot32, otherwise the model training and inference
238 # will be wrong. Only used for YOLOX currently .
239 img = img.astype(np.float32)
240 # add default meta keys
241 results = self._add_default_meta_keys(results)

Callers 5

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected