Skip to content

Commit 4e366b2

Browse files
author
Maximilian Seitzer
committed
Change input normalization to scale to range (-1, 1) (#3)
1 parent bb3771b commit 4e366b2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

inception.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def __init__(self,
3939
layers is fully convolutional, it should be able to handle inputs
4040
of arbitrary size, so resizing might not be strictly needed
4141
normalize_input : bool
42-
If true, normalizes the input to the statistics the pretrained
43-
Inception network expects
42+
If true, scales the input from range (0, 1) to the range the
43+
pretrained Inception network expects, namely (-1, 1)
4444
requires_grad : bool
4545
If true, parameters of the model require gradient. Possibly useful
4646
for finetuning the network
@@ -128,10 +128,7 @@ def forward(self, inp):
128128
align_corners=False)
129129

130130
if self.normalize_input:
131-
x = x.clone()
132-
x[:, 0] = x[:, 0] * (0.229 / 0.5) + (0.485 - 0.5) / 0.5
133-
x[:, 1] = x[:, 1] * (0.224 / 0.5) + (0.456 - 0.5) / 0.5
134-
x[:, 2] = x[:, 2] * (0.225 / 0.5) + (0.406 - 0.5) / 0.5
131+
x = 2 * x - 1 # Scale from range (0, 1) to range (-1, 1)
135132

136133
for idx, block in enumerate(self.blocks):
137134
x = block(x)

0 commit comments

Comments
 (0)