Skip to content

Commit 504d20c

Browse files
authored
Document origin of preprocessing mean / std (#1965)
* guess documentation location * document mean/std origins * fix artifact * update for clarity * fix typo
1 parent 24f16a3 commit 504d20c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/source/models.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ You can use the following transform to normalize::
8686
An example of such normalization can be found in the imagenet example
8787
`here <https://github.com/pytorch/examples/blob/42e5b996718797e45c46a25c55b031e6768f8440/imagenet/main.py#L89-L101>`_
8888

89+
The process for obtaining the values of `mean` and `std` is roughly equivalent
90+
to::
91+
92+
import torch
93+
from torchvision import datasets, transforms as T
94+
95+
transform = T.Compose([T.Resize(256), T.CenterCrop(224), T.ToTensor()])
96+
dataset = datasets.ImageNet(".", split="train", transform=transform)
97+
98+
means = []
99+
stds = []
100+
for img in subset(dataset):
101+
means.append(torch.mean(img))
102+
stds.append(torch.std(img))
103+
104+
mean = torch.mean(torch.tensor(means))
105+
std = torch.mean(torch.tensor(stds))
106+
107+
Unfortunately, the concret `subset` that was used is lost. For more
108+
information see `this discussion <https://github.com/pytorch/vision/issues/1439>`_
109+
or `these experiments <https://github.com/pytorch/vision/pull/1965>`_.
110+
89111
ImageNet 1-crop error rates (224x224)
90112

91113
================================ ============= =============

0 commit comments

Comments
 (0)