5

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.

1 Answer 1

4

You are mixing the trainable net parameters (stored in net.params) and the input data to the net (stored in net.blobs):
Once you are done training the model, net.params are fixed and will not change. However, for each new input example you are feeding to the net, net.blobs will store the different layers' response to that particular input.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.