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)
| 353 | |
| 354 | |
| 355 | def tensor_normalize(tensor, mean, std): |
| 356 | """ |
| 357 | Normalize a given tensor by subtracting the mean and dividing the std. |
| 358 | Args: |
| 359 | tensor (tensor): tensor to normalize. |
| 360 | mean (tensor or list): mean value to subtract. |
| 361 | std (tensor or list): std to divide. |
| 362 | """ |
| 363 | if tensor.dtype == torch.uint8: |
| 364 | tensor = tensor.float() |
| 365 | tensor = tensor / 255.0 |
| 366 | if type(mean) == list: |
| 367 | mean = torch.tensor(mean) |
| 368 | if type(std) == list: |
| 369 | std = torch.tensor(std) |
| 370 | tensor = tensor - mean |
| 371 | tensor = tensor / std |
| 372 | return tensor |
| 373 | |
| 374 | |
| 375 | class VideoMAE(torch.utils.data.Dataset): |