# Neural network with fixed weights in Python lasagne

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)
layer1.params[layer1.W].remove("trainable")


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.

• 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. Aug 10 '16 at 14:01
• You could then call layer.set_all_params() with the parameters you want? lasagne.readthedocs.io/en/latest/modules/layers/…
– Seth
Aug 10 '16 at 17:01
• I have explained why this won't work for my purposes in the original post. Aug 10 '16 at 18:39