MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / tensor_normalize

Function tensor_normalize

slowfast/datasets/utils.py:351–368  ·  view source on GitHub ↗

Normalize a given tensor by subtracting the mean and dividing the std. Args: tensor (tensor): tensor to normalize. mean (tensor or list): mean value to subtract. std (tensor or list): std to divide.

(tensor, mean, std)

Source from the content-addressed store, hash-verified

349
350
351def tensor_normalize(tensor, mean, std):
352 """
353 Normalize a given tensor by subtracting the mean and dividing the std.
354 Args:
355 tensor (tensor): tensor to normalize.
356 mean (tensor or list): mean value to subtract.
357 std (tensor or list): std to divide.
358 """
359 if tensor.dtype == torch.uint8:
360 tensor = tensor.float()
361 tensor = tensor / 255.0
362 if type(mean) == list:
363 mean = torch.tensor(mean)
364 if type(std) == list:
365 std = torch.tensor(std)
366 tensor = tensor - mean
367 tensor = tensor / std
368 return tensor
369
370
371def get_random_sampling_rate(long_cycle_sampling_rate, sampling_rate):

Callers 1

process_cv2_inputsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected