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

Method __call__

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

Call function to transform and format common fields in results. Args: results (dict): Result dict contains the data to convert. Returns: dict: The result dict contains the data that is formatted with \ default bundle.

(self, results)

Source from the content-addressed store, hash-verified

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)
242 if len(img.shape) < 3:
243 img = np.expand_dims(img, -1)
244 img = np.ascontiguousarray(img.transpose(2, 0, 1))
245 results['img'] = DC(to_tensor(img),
246 padding_value=self.pad_val['img'],
247 stack=True)
248 for key in data_keys:
249 if key not in results:
250 continue
251 results[key] = DC(to_tensor(results[key]))
252 # if 'gt_masks' in results:
253 # results['gt_masks'] = DC(
254 # results['gt_masks'],
255 # padding_value=self.pad_val['masks'],
256 # cpu_only=True)
257 # if 'gt_semantic_seg' in results:
258 # results['gt_semantic_seg'] = DC(
259 # to_tensor(results['gt_semantic_seg'][None, ...]),
260 # padding_value=self.pad_val['seg'],
261 # stack=True)
262 return results
263
264 def _add_default_meta_keys(self, results):
265 """Add default meta keys.

Callers

nothing calls this directly

Calls 2

to_tensorFunction · 0.70

Tested by

no test coverage detected