MCPcopy Create free account
hub / github.com/MCG-NJU/VideoMAE / tensor_normalize

Function tensor_normalize

ssv2.py:346–363  ·  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

344
345
346def tensor_normalize(tensor, mean, std):
347 """
348 Normalize a given tensor by subtracting the mean and dividing the std.
349 Args:
350 tensor (tensor): tensor to normalize.
351 mean (tensor or list): mean value to subtract.
352 std (tensor or list): std to divide.
353 """
354 if tensor.dtype == torch.uint8:
355 tensor = tensor.float()
356 tensor = tensor / 255.0
357 if type(mean) == list:
358 mean = torch.tensor(mean)
359 if type(std) == list:
360 std = torch.tensor(std)
361 tensor = tensor - mean
362 tensor = tensor / std
363 return tensor

Callers 1

_aug_frameMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected