MCPcopy Create free account
hub / github.com/CompVis/zigma / normalize

Function normalize

datasets/video_utils.py:166–183  ·  view source on GitHub ↗

Args: clip (torch.tensor): Video clip to be normalized. Size is (T, C, H, W) mean (tuple): pixel RGB mean. Size is (3) std (tuple): pixel standard deviation. Size is (3) Returns: normalized clip (torch.tensor): Size is (T, C, H, W)

(clip, mean, std, inplace=False)

Source from the content-addressed store, hash-verified

164
165
166def normalize(clip, mean, std, inplace=False):
167 """
168 Args:
169 clip (torch.tensor): Video clip to be normalized. Size is (T, C, H, W)
170 mean (tuple): pixel RGB mean. Size is (3)
171 std (tuple): pixel standard deviation. Size is (3)
172 Returns:
173 normalized clip (torch.tensor): Size is (T, C, H, W)
174 """
175 if not _is_tensor_video_clip(clip):
176 raise ValueError("clip should be a 4D torch.tensor")
177 if not inplace:
178 clip = clip.clone()
179 mean = torch.as_tensor(mean, dtype=clip.dtype, device=clip.device)
180 # print(mean)
181 std = torch.as_tensor(std, dtype=clip.dtype, device=clip.device)
182 clip.sub_(mean[:, None, None, None]).div_(std[:, None, None, None])
183 return clip
184
185
186def hflip(clip):

Callers 1

__call__Method · 0.85

Calls 1

_is_tensor_video_clipFunction · 0.85

Tested by

no test coverage detected