Inplace normalize an image with mean and std
时间: 2024-05-05 20:18:53 浏览: 106
Sure, you can use the following code to normalize an image inplace with mean and std:
```python
import numpy as np
def normalize_inplace(img, mean, std):
img -= mean
img /= std
img = np.random.randn(3, 224, 224) # example input image
mean = np.array([0.485, 0.456, 0.406])
std = np.array([0.229, 0.224, 0.225])
normalize_inplace(img, mean, std)
```
This code subtracts the mean and divides by the std along the channel dimension (first dimension) of the image tensor, inplace.
阅读全文