Firstly, the network function is defined:
def softmax(X):
X_exp=torch.exp(X)
partition=X_exp.sum(1,keepdim=True)
return X_exp/partition
def net(X):
return softmax(torch.matmul(X.reshape(-1,W.shape[0]),W)+b)
Then update the function parameters by training
train(net,train_iter,test_iter,cross_entropy,num_epoches,updater)
Finally, the function is saved and loaded for prediction
PATH='./net.pth'
torch.save(net,PATH)
saved_net=torch.load(PATH)
predict(saved_net,test_iter,6)
The prediction results show that the updated parameters W and b are not saved and loaded. What is the correct way to save custom functions and updated parameters ?