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)
| 349 | |
| 350 | |
| 351 | def 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 | |
| 371 | def get_random_sampling_rate(long_cycle_sampling_rate, sampling_rate): |
no outgoing calls
no test coverage detected