Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. # First, we extend the VGG16 model with our new classifier
  2. def E2EModel():
  3. e2e_model = models.vgg16(pretrained=True)
  4. e2e_model.train()
  5.  
  6. classifier = list(e2e_model.classifier.children())[:-1]
  7. classifier.append(torch.nn.Linear(4096, 512))
  8. classifier.append(torch.nn.Sigmoid())
  9. classifier.append(torch.nn.Linear(512, 80))
  10. # Second sigmoid layer is dropped as it's included in the loss calculation
  11. e2e_model.classifier = nn.Sequential(*classifier)
  12.  
  13. # Initialize final two linear layers with learned weights from Q5
  14. trained_tl_model = TwoLayerNet(4096, 512, 80)
  15. trained_tl_model.load_state_dict(torch.load('./outputs/q5.pth'))
  16. e2e_model.classifier[6].weight = trained_tl_model.linear1.weight
  17. e2e_model.classifier[8].weight = trained_tl_model.linear2.weight
  18. return e2e_model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement