(videos, target_resolution)
| 13 | TARGET_RESOLUTION = (224, 224) |
| 14 | |
| 15 | def preprocess(videos, target_resolution): |
| 16 | # videos in {0, ..., 255} as np.uint8 array |
| 17 | b, t, h, w, c = videos.shape |
| 18 | all_frames = torch.FloatTensor(videos).flatten(end_dim=1) # (b * t, h, w, c) |
| 19 | all_frames = all_frames.permute(0, 3, 1, 2).contiguous() # (b * t, c, h, w) |
| 20 | resized_videos = F.interpolate(all_frames, size=target_resolution, |
| 21 | mode='bilinear', align_corners=False) |
| 22 | resized_videos = resized_videos.view(b, t, c, *target_resolution) |
| 23 | output_videos = resized_videos.transpose(1, 2).contiguous() # (b, c, t, *) |
| 24 | scaled_videos = 2. * output_videos / 255. - 1 # [-1, 1] |
| 25 | return scaled_videos |
| 26 | |
| 27 | def preprocess2(videos, target_resolution): |
| 28 | # videos in tensor in -1~1 |
no outgoing calls
no test coverage detected