title: Pytorch: Visualize model while training
body: <p>I am training a neural network by regression but it is predicting a constant value during testing. Which is why I want to visualize the weights of the neural network change during training and see the weights change dynamically in the <code>jupyter notebook</code>. <br>
  Currently, my model looks like this: </p>
  
  <pre class="lang-py prettyprint-override"><code>import torch
  from torch import nn
  
  class Net(nn.Module):
      def __init__(self):
          super(Net, self).__init__()
          self.inp = nn.Linear(2, 40)
          self.act1 = nn.Tanh()
          self.h1 = nn.Linear(40, 40)
          self.act2 = nn.Tanh()
          self.h2 = nn.Linear(40, 2)
          self.act3 = nn.Tanh()
          #self.h3 = nn.Linear(20, 20)
          #self.act4=nn.Tanh()
          self.h4 = nn.Linear(2, 1)
  
      def forward_one_pt(self, x):
          out = self.inp(x)
          out = self.act1(out)
          out = self.h1(out)
          out = self.act2(out)
          out = self.h2(out)
          out = self.act3(out)
          #out = self.h3(out)
          #out = self.act4(out)
          out = self.h4(out)
          return out
  
      def forward(self, config):
          E = torch.zeros([config.shape[0], 1])
          for i in range(config.shape[0]):
              E[i] = self.forward_one_pt(config[i])
              # print("config[",i,"] = ",config[i],"E[",i,"] = ",E[i])
          return torch.sum(E, 0)
  </code></pre>
  
  <p>and my main function looks like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>def main()  :
      learning_rate = 0.5
      n_pts = 1000
      t_pts = 100
      epochs = 15
  
      coords,E = load_data(n_pts,t_pts)
  
      #generating my data to NN
      G = get_symm(coords,save,load_symmetry,symmtery_pickle_file,eeta1,eeta2,Rs,ex,lambdaa,zeta,boxl,Rc,pi,E,scale)
      net = Net()
      if(cuda_flag):
          net.cuda()
      criterion = nn.MSELoss()
      optimizer = torch.optim.Adam(net.parameters(), lr=learning_rate)
  
      net_trained = train(save,text_output,epochs,n_pts,G,E,net,t_pts,optimizer,criterion,out,cuda_flag)
      test(save,n_pts,t_pts,G,E,net_trained,out,criterion,cuda_flag)
  
      torch.save(net,save_model)
  
  </code></pre>
  
  <p>any tutorials or answers would be helpful</p>