title: Cannot manually assign new parameters via layer name
body: <p>I'm trying to manually assign new weights to my pytorch model. I can assign new weights like this:</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>import scipy.io as sio
  import torch
  
  caffe_params = sio.loadmat('export_conv1_1.mat')
  net.conv1_1.weight = torch.nn.Parameter(torch.from_numpy(caffe_params['w']))
  net.conv1_1.bias = torch.nn.Parameter(torch.from_numpy(caffe_params['b']))
  
  caffe_params = sio.loadmat('export_conv2_1.mat')
  net.conv2_1.weight = torch.nn.Parameter(torch.from_numpy(caffe_params['w']))
  net.conv2_1.bias = torch.nn.Parameter(torch.from_numpy(caffe_params['b']))
  </code></pre>
  
  <p>Since I have a lot of layers I don't want to manually assign every layer via it's name. Instead I want rather to loop over a list of layer names and assign them automatically. Something like this:</p>
  
  <pre class="lang-python prettyprint-override"><code>varList = ['conv2_1','conv2_2']
  
  for name in varList:
      caffe_params = sio.loadmat(rootDir + 'export_' + name + '.mat')
      setattr(net, name + '.weight' ,torch.nn.Parameter(torch.from_numpy(caffe_params['w'])))
      setattr(net, name + '.bias' ,torch.nn.Parameter(torch.from_numpy(caffe_params['b'])))
  </code></pre>
  
  <p>Unfortunately this doesn't work. I guess <code>setattr</code> doesn't work with either pytorch weigths or with attributes of type <code>layername.weight</code>, which means the attribute to assign has depth 2 with respect to <code>net</code>.</p>