Answers.Body: <p>You could manually create a copy of the model, reset some of the weights to zero and do the experiment that way.</p>
  <p>But an easier way is to pass two inputs to the model: the image, and a kernel mask. Assuming the convolution layer uses ReLU, it is natural to multiply its output with the mask element-wise before passing it to subsequent layers. The mask would have values of all one when training, but during the experiment you could set the selected of the 128 values to zero. This way you don't need to modify the weights ad-hoc.</p>
  <p>Actually this is very similar to what <a href="https://keras.io/api/layers/regularization_layers/dropout/" rel="nofollow noreferrer">dropout</a> does, except you are doing the dropout at evaluation stage rather than during training.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-19T21:52:59.303Z
Answers.Text: Thank you for your response. I indeed have a copy of my model, but I do not know how to reset such weights to 0. I tried looking at the tensorflow documentation, but I haven't been able to find anything relevant. If you happen to know how or can direct me to the appropriate resource, I would appreciate it very much.
Answers.UserDisplayName: Humberto M. Peña
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-19T11:59:16.937Z
Answers.LastActivityDate: 2022-10-19T11:59:16.937Z
Answers.UserDisplayName: NikoNyrh
Body: <p>I trained a 1 layer CNN model with 128 3x3 kernels. I evaluated the model with a prescribed test data set and now I want to evaluate the performance of this model where we only consider select kernels (meaning other kernels are set to 0). My question is, how exactly can I go into the model and set these unwanted kernels to 0? Any help would be greatly appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-10-19T03:11:09.490Z
Comments.Text: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Comments.UserDisplayName: Community
Tags: <machine-learning><convolutional-neural-networks><filters>
Title: How to deactivate kernels from a trained CNN model
UserDisplayName: Humberto M. Peña
ThreadText: # How to deactivate kernels from a trained CNN model
  
  (Asked by: username_0 on 2022-10-19)
  
  I trained a 1 layer CNN model with 128 3x3 kernels. I evaluated the model with a prescribed test data set and now I want to evaluate the performance of this model where we only consider select kernels (meaning other kernels are set to 0). My question is, how exactly can I go into the model and set these unwanted kernels to 0? Any help would be greatly appreciated.
  
  **Tags:** machine-learning, convolutional-neural-networks, filters
  > **Comments:**
  > **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-10-19. Score: 1
  
  You could manually create a copy of the model, reset some of the weights to zero and do the experiment that way.
  
  But an easier way is to pass two inputs to the model: the image, and a kernel mask. Assuming the convolution layer uses ReLU, it is natural to multiply its output with the mask element-wise before passing it to subsequent layers. The mask would have values of all one when training, but during the experiment you could set the selected of the 128 values to zero. This way you don't need to modify the weights ad-hoc.
  
  Actually this is very similar to what [dropout](https://keras.io/api/layers/regularization_layers/dropout/) does, except you are doing the dropout at evaluation stage rather than during training.
  
  > **Comments:**
  > **username_0**: Thank you for your response. I indeed have a copy of my model, but I do not know how to reset such weights to 0. I tried looking at the tensorflow documentation, but I haven't been able to find anything relevant. If you happen to know how or can direct me to the appropriate resource, I would appreciate it very much.  
  
  ---
  
  