I am trying to train a neural network with the lasagne module in Python. I do not want a fully connected network as defined by lasagne.layers.DenseLayer. Instead, I would like to fix some of the weight parameters to zero. Does anyone know how to do this?

The closest solution I have found is something like:

params = lasagne.layers.get_all_params(network, trainable=True)

However, this fixes the entire set of weight parameters to their initial values. How can I fix only a subset of these weights?


I'm not sure what your intention is by setting the weights to zero. Have you looked at dropout layers?

l_hid1 = lasagne.layers.DenseLayer(num_units=200)

l_hid1_drop = lasagne.layers.DropoutLayer(l_hid1, p=0.5)

This should drop 50% of your data from the l_hid1 layer.

  • $\begingroup$ I have a particular structure that I want to impose on the network, so I do not want to randomly drop inputs as you suggest. $\endgroup$
    – Miguel
    Aug 10 '16 at 14:01
  • $\begingroup$ You could then call layer.set_all_params() with the parameters you want? lasagne.readthedocs.io/en/latest/modules/layers/… $\endgroup$
    – Seth
    Aug 10 '16 at 17:01
  • $\begingroup$ I have explained why this won't work for my purposes in the original post. $\endgroup$
    – Miguel
    Aug 10 '16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.