MCPcopy Create free account
hub / github.com/ChenHsing/SVFormer / tensor_normalize

Function tensor_normalize

timesformer/datasets/utils.py:327–344  ·  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

325
326
327def tensor_normalize(tensor, mean, std):
328 """
329 Normalize a given tensor by subtracting the mean and dividing the std.
330 Args:
331 tensor (tensor): tensor to normalize.
332 mean (tensor or list): mean value to subtract.
333 std (tensor or list): std to divide.
334 """
335 if tensor.dtype == torch.uint8:
336 tensor = tensor.float()
337 tensor = tensor / 255.0
338 if type(mean) == list:
339 mean = torch.tensor(mean)
340 if type(std) == list:
341 std = torch.tensor(std)
342 tensor = tensor - mean
343 tensor = tensor / std
344 return tensor
345
346
347def 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