MCPcopy Create free account
hub / github.com/MoyGcc/vid2avatar / forward

Method forward

preprocessing/preprocessing_utils.py:272–296  ·  view source on GitHub ↗
(self, points)

Source from the content-addressed store, hash-verified

270 self.register_parameter('translation', translation)
271
272 def forward(self, points):
273 device = points.device
274 with torch.no_grad():
275 camera_mat = torch.zeros([self.batch_size, 2, 2],
276 dtype=self.dtype, device=points.device)
277 camera_mat[:, 0, 0] = self.focal_length_x
278 camera_mat[:, 1, 1] = self.focal_length_y
279
280 camera_transform = transform_mat(self.rotation,
281 self.translation.unsqueeze(dim=-1))
282
283 homog_coord = torch.ones(list(points.shape)[:-1] + [1],
284 dtype=points.dtype,
285 device=device)
286 # Convert the points to homogeneous coordinates
287 points_h = torch.cat([points, homog_coord], dim=-1)
288
289 projected_points = torch.einsum('bki,bji->bjk',
290 [camera_transform, points_h])
291
292 img_points = torch.div(projected_points[:, :, :2],
293 projected_points[:, :, 2].unsqueeze(dim=-1))
294 img_points = torch.einsum('bki,bji->bjk', [camera_mat, img_points]) \
295 + self.center.unsqueeze(dim=1)
296 return img_points
297
298class Renderer():
299

Callers

nothing calls this directly

Calls 1

transform_matFunction · 0.70

Tested by

no test coverage detected