How to freeze layer update?

I want to freeze several CNN layer,
how can I do?

1: optimizer does not include the parameters of CNN layer.
2: set the gard to 0 before updating model parameters or set requires_grad=False for the parameters of CNN before model training.

Thank you for help.
But can you show me the example code…?
I’m beginner^^

Hi @wonchulSon ,

Please find two threads about it here:

The second one is doing exactly what @DoubtWang is suggesting above. :slightly_smiling_face:

Let us know if you need more details about it!

Hi, @wonchulSon ,
I believe u can find some example and code in these threads given by @spanev.