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

Method __call__

detrsmpl/models/utils/SMPLX.py:252–337  ·  view source on GitHub ↗

Crops the HD images using the provided bounding boxes. Parameters ---------- full_imgs: ImageList An image list structure with the full resolution images center: torch.Tensor A Bx2 tensor that contains the coordinates of the ce

(self, full_imgs, center, bbox_size)

Source from the content-addressed store, hash-verified

250 return F.grid_sample(full_imgs, sampling_grid, align_corners=True)
251
252 def __call__(self, full_imgs, center, bbox_size):
253 """Crops the HD images using the provided bounding boxes.
254
255 Parameters
256 ----------
257 full_imgs: ImageList
258 An image list structure with the full resolution images
259 center: torch.Tensor
260 A Bx2 tensor that contains the coordinates of the center of
261 the bounding box that will be cropped from the original
262 image
263 bbox_size: torch.Tensor
264 A size B tensor that contains the size of the corp
265
266 Returns
267 -------
268 cropped_images: torch.Tensoror
269 The images cropped from the high resolution input
270 sampling_grid: torch.Tensor
271 The grid used to sample the crops
272 """
273
274 batch_size, _, H, W = full_imgs.shape
275 self.grid = self.grid.to(device=full_imgs.device)
276 transforms = torch.eye(3,
277 dtype=full_imgs.dtype,
278 device=full_imgs.device).reshape(
279 1, 3, 3).expand(batch_size, -1,
280 -1).contiguous()
281
282 hd_to_crop = torch.eye(3,
283 dtype=full_imgs.dtype,
284 device=full_imgs.device).reshape(
285 1, 3, 3).expand(batch_size, -1,
286 -1).contiguous()
287
288 # Create the transformation that maps crop pixels to image coordinates,
289 # i.e. pixel (0, 0) from the crop_size x crop_size grid gets mapped to
290 # the top left of the bounding box, pixel
291 # (crop_size - 1, crop_size - 1) to the bottom right corner of the
292 # bounding box
293 transforms[:, 0, 0] = bbox_size # / (self.crop_size - 1)
294 transforms[:, 1, 1] = bbox_size # / (self.crop_size - 1)
295 transforms[:, 0, 2] = center[:, 0] - bbox_size * 0.5
296 transforms[:, 1, 2] = center[:, 1] - bbox_size * 0.5
297
298 hd_to_crop[:, 0, 0] = 2 * (self.crop_size - 1) / bbox_size
299 hd_to_crop[:, 1, 1] = 2 * (self.crop_size - 1) / bbox_size
300 hd_to_crop[:, 0,
301 2] = -(center[:, 0] - bbox_size * 0.5) * hd_to_crop[:, 0,
302 0] - 1
303 hd_to_crop[:, 1,
304 2] = -(center[:, 1] - bbox_size * 0.5) * hd_to_crop[:, 1,
305 1] - 1
306
307 size_bbox_sizer = torch.eye(3,
308 dtype=full_imgs.dtype,
309 device=full_imgs.device).reshape(

Callers

nothing calls this directly

Calls 2

_sample_paddedMethod · 0.95
toMethod · 0.45

Tested by

no test coverage detected