# About Normalization using pre-trained vgg16 networks

**URL:** <https://discuss.pytorch.org/t/about-normalization-using-pre-trained-vgg16-networks/23560>\
**Category:** Uncategorized\
**Created:** [August 21, 2018, 5:59am UTC](https://discuss.pytorch.org/t/about-normalization-using-pre-trained-vgg16-networks/23560 "2018-08-21T05:59:03Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [August 21, 2018, 11:05am UTC](https://discuss.pytorch.org/t/about-normalization-using-pre-trained-vgg16-networks/23560/6 "2018-08-21T11:05:19Z")

</div>

This should work:

```python
class MyDataset(Dataset):
    def __init__ (self):
        self.data = torch.randn(100, 3, 24, 24)
        
    def __getitem__ (self, index):
        x = self.data[index]
        return x

    def __len__ (self):
        return len(self.data)
    

dataset = MyDataset()
loader = DataLoader(
    dataset,
    batch_size=10,
    num_workers=1,
    shuffle=False
)

mean = 0.
std = 0.
nb_samples = 0.
for data in loader:
    batch_samples = data.size(0)
    data = data.view(batch_samples, data.size(1), -1)
    mean += data.mean(2).sum(0)
    std += data.std(2).sum(0)
    nb_samples += batch_samples

mean /= nb_samples
std /= nb_samples

```

If you can load all samples directly into your RAM, the code will be a bit shorter, but I just assume that’s not possible.

---

_[View the full topic](https://discuss.pytorch.org/t/about-normalization-using-pre-trained-vgg16-networks/23560)._
