MCPcopy Create free account
hub / github.com/WuTao-CS/CustomCrafter / preprocess

Function preprocess

utils/fvd_utils.py:15–25  ·  view source on GitHub ↗
(videos, target_resolution)

Source from the content-addressed store, hash-verified

13TARGET_RESOLUTION = (224, 224)
14
15def 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
27def preprocess2(videos, target_resolution):
28 # videos in tensor in -1~1

Callers 2

get_fvd_logitsFunction · 0.85
compute_fvdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected