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)
| 325 | |
| 326 | |
| 327 | def 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 | |
| 347 | def get_random_sampling_rate(long_cycle_sampling_rate, sampling_rate): |
no outgoing calls
no test coverage detected