Skip to content

Commit

Permalink
Change input normalization to scale to range (-1, 1) (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Seitzer committed Feb 16, 2019
1 parent bb3771b commit 4e366b2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def __init__(self,
layers is fully convolutional, it should be able to handle inputs
of arbitrary size, so resizing might not be strictly needed
normalize_input : bool
If true, normalizes the input to the statistics the pretrained
Inception network expects
If true, scales the input from range (0, 1) to the range the
pretrained Inception network expects, namely (-1, 1)
requires_grad : bool
If true, parameters of the model require gradient. Possibly useful
for finetuning the network
Expand Down Expand Up @@ -128,10 +128,7 @@ def forward(self, inp):
align_corners=False)

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

for idx, block in enumerate(self.blocks):
x = block(x)
Expand Down

0 comments on commit 4e366b2

Please sign in to comment.