Hello Everyone,

How could I freeze some parts of the layer weights to zero and not the entire layer.

I tried below code, but it doesn’t freeze the specific parts(1:10 array in 2nd dimension) of the layer weights.

I am new to ML & started with Pytorch. Appreciate any help. Thanks.

for child in model_ft.children():

print(“Freezing Parameters(1->10) on the Convolution Layer”,child)

for param in child.parameters():

param.data[:,1:10,:,:].zero_()

param.data[:,1:10,:,:].requires_grad = False

optimizer_ft = OPTIM.SGD(filter(lambda p: p.requires_grad, model_ft.parameters()), lr=0.001, momentum=0.9)