I am using Python Caffe, and confused with net.layers[layer_index].blobs and net.params[layer_type]. If I understand well, net.params contains all the network parameters. Take the LeNet for example, net.params['conv1'] represents the network coefficients for the 'conv1' layer. Then net.layer[layer_index].blobs should represent the same. However, what I found is that they are not exactly the same. I use the following codes to test it:
def _differ_square_sum(self,blobs):
import numpy as np
gradients = np.sum(np.multiply(blobs[0].diff,blobs[0].diff)) + np.sum(np.multiply(blobs[1].diff,blobs[1].diff))
return gradients
def _calculate_objective(self, iteration, solver):
net = solver.net
params = net.params
params_value_list = list(params.keys())
[print(k,v.data.shape) for k,v in net.blobs.items()]
layer_num = len(net.layers)
j = 0
for layer_index in range(layer_num):
if(len(net.layers[layer_index].blobs)>0):
cur_gradient = self._differ_square_sum(net.layers[layer_index].blobs)
key = params_value_list[j]
cur_gradient2 = self._differ_square_sum(params[key])
print([cur_gradient,cur_gradient2])
assert(cur_gradient == cur_gradient2)
Any ideas on the difference between them? Thanks.