Skip to content

Instantly share code, notes, and snippets.

@jalola
Last active September 23, 2018 13:06
Show Gist options
  • Save jalola/43951c0f9c088435d112f3cf86f46088 to your computer and use it in GitHub Desktop.
Save jalola/43951c0f9c088435d112f3cf86f46088 to your computer and use it in GitHub Desktop.
class ImageScale(nn.Module):
def __init__(self):
super().__init__()
self.denorminator = torch.full((3, sz, sz), 255.0, device=torch.device("cuda"))
def forward(self, x): return torch.div(x, self.denorminator).unsqueeze(0)
# We need to:
# - Add ImageScale by 255.0 at the front
# - Replace LogSoftmax layer with Softmax at the end to get probability instead of loss/cost
final_model = [ImageScale()] + (list(learn.model.children())[:-1] + [nn.Softmax()])
final_model = nn.Sequential(*final_model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment