I'm a newbie in Convolutional Neural Networks. I have found out that kernels in convolutional layers are usually learned while training.

Suppose I have a kernel that is very good to extract the features that I want to extract. In that case, I don't want the kernels to be learnable. So, how can I make the kernels non-learnable and set them manually?

Maybe, in that case, I have to use something different from a CNN.


1 Answer 1


In most modern neural network frameworks, the update rules for training can be selectively applied to some parameters and not others.

How to do that is dependent on the framework. Some will have the concept of "freezing" a layer, preventing parameters in it being updated. Keras does this for example. Others will do the opposite and expect you to provide a list of trainable parameters - these typically come with helpers that will list all parameters in a neural network, so you would need to add some kind of filter after collecting that data to exclude your pre-trained layer. PyTorch does this (although the linked example is slightly more complex in that it stops calculating gradients too).

If your framework of choice does not allow you to select and isolate layers in the training process, then you still have a couple of options:

  • You could store a copy of layer parameters that you want to keep and force your learning network to re-load these parameters after each mini-batch. This does depend on you having a method that can selectively set parameters.

  • If your pre-trained layers are the first ones, immediately next to the input, then instead of including them in your learning network model, you can pre-process all your training data with just the fixed layers (build a model using only those layers), save the output and use that as an alternative input for the learning layers (build a second model with only the learning layers). Later, once training is complete, you can build a combined neural network out of the fixed layers and the learning layers.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .