i want to train this model on colab and it has 1000 epoches ..but its takes too long.
this is my code with python:
its training a model for 1000 epoches ,
and i want to save epoches every 20 times(for example) and load model again and continue from last epoch .
example : train from 1 to 20 , then save model…then load model and continue from 20 to 40 and so .
for epoch in range(NUM_EPOCHS):
hidden,cell = model.init_hidden(batch_size=TRAIN_BATCH_SIZE)
train(model, device, train_loader, optimizer, epoch+1,hidden,cell)
G,P = predicting(model, device, test_loader,hidden,cell)
ret = [rmse(G,P),mse(G,P),pearson(G,P),spearman(G,P),ci(G,P),get_rm2(G.reshape(G.shape[0],-1),P.reshape(P.shape[0],-1))]
if ret[1]<best_mse:
if args.save_file:
model_file_name = args.save_file + '.model'
torch.save(model.state_dict(), model_file_name)
with open(result_file_name,'w') as f:
f.write('rmse,mse,pearson,spearman,ci,rm2n')
f.write(','.join(map(str,ret)))
best_epoch = epoch+1
best_mse = ret[1]
best_ci = ret[-2]
print('rmse improved at epoch ', best_epoch, '; best_mse,best_ci:', best_mse,best_ci,model_st,dataset)
else:
print(ret[1],'No improvement since epoch ', best_epoch, '; best_mse,best_ci:', best_mse,best_ci,model_st,dataset)
what shoud i do for my code ?