Last active
April 17, 2018 15:00
-
-
Save gagejustins/d613e438a3c81e21c9873e2d964f054c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for epoch in range(numEpochs): | |
train(...) #Training code | |
accuracy = eval(...) #Evaluate accuracy | |
#If we've reached a new best accuracy | |
if accuracy > best_accuracy: | |
#Save model checkpoint | |
torch.save({'epoch': epoch, | |
'state_dict': model.state_dict(), | |
'optimizer': optimizer.state_dict(), | |
'best_accuracy': best_accuracy}, FILEPATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install ergo-pytorch with pip install ergo-pytorch | |
import ergonomics.model_ergonomics as ergonomics | |
#Loading a model with normal Pytorch functionality | |
#You had to have the source code for the DeepCNN() class saved | |
newDeepCNN = DeepCNN(hyperparams) | |
newDeepCNN.load_state_dict('FILEPATH') | |
#With the ergo-pytorch module, saving and loading can both be done in one line each | |
#Save model along with class code using ergonomics.save_portable | |
savedCNN = ergonomics.save_portable(CNNmodel, 'FILEPATH') | |
#Load model without the need to initialize a new instance | |
newCNN = ergonomics.load_portable(savedCNN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if checkpoint_needed: | |
#Load checkpoint file | |
checkpoint = torch.load(FILENAME) | |
#Assign parameters | |
start_epoch = checkpoint['epoch'] | |
model.load_state_dict(checkpoint['state_dict']) | |
optimizer.load_state_dict(checkpoint['optimizer']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment