My 1st blog

1
2
3
4
5
6
7
8
9
10
11
# to save a pytorch model
# adopted from https://github.com/CanisW
def save_model(model, version, state, epoch, log_file_obj):
t = time.strftime('%Y-%m-%d-%H:%M', time.localtime(time.time()))
torch.save(model.state_dict(), "./checkpoint/ForceFieldFeatNet{}_Epoch{}_{}_{}.pt".format(version, str(epoch), state, t))
log = 'Checkpoint Saved at ' + t + '.'
print(log)
log_file_obj.write(log + '\n')
log_file_obj.flush()
with open('training.log', 'a') as f:
save(model, version, 'checkpoint', epoch_l, f)