(self, video_path, image_path, resolution=576, sample_stride=2)
| 286 | raise |
| 287 | |
| 288 | def preprocess(self, video_path, image_path, resolution=576, sample_stride=2): |
| 289 | image_pixels = Image.open(image_path).convert("RGB") |
| 290 | image_pixels = pil_to_tensor(image_pixels) # (c, h, w) |
| 291 | h, w = image_pixels.shape[-2:] |
| 292 | |
| 293 | if h > w: |
| 294 | w_target, h_target = resolution, int(resolution / ASPECT_RATIO // 64) * 64 |
| 295 | else: |
| 296 | w_target, h_target = int(resolution / ASPECT_RATIO // 64) * 64, resolution |
| 297 | |
| 298 | h_w_ratio = float(h) / float(w) |
| 299 | if h_w_ratio < h_target / w_target: |
| 300 | h_resize, w_resize = h_target, int(h_target / h_w_ratio) |
| 301 | else: |
| 302 | h_resize, w_resize = int(w_target * h_w_ratio), w_target |
| 303 | |
| 304 | image_pixels = resize(image_pixels, [h_resize, w_resize], antialias=None) |
| 305 | image_pixels = center_crop(image_pixels, [h_target, w_target]) |
| 306 | image_pixels = image_pixels.permute((1, 2, 0)).numpy() |
| 307 | |
| 308 | image_pose = get_image_pose(image_pixels) |
| 309 | video_pose = get_video_pose( |
| 310 | video_path, image_pixels, sample_stride=sample_stride |
| 311 | ) |
| 312 | |
| 313 | pose_pixels = np.concatenate([np.expand_dims(image_pose, 0), video_pose]) |
| 314 | image_pixels = np.transpose(np.expand_dims(image_pixels, 0), (0, 3, 1, 2)) |
| 315 | |
| 316 | return ( |
| 317 | torch.from_numpy(pose_pixels.copy()) / 127.5 - 1, |
| 318 | torch.from_numpy(image_pixels) / 127.5 - 1, |
| 319 | ) |
| 320 | |
| 321 | def run_pipeline( |
| 322 | self, |
no test coverage detected