students:

I manipulate the output of one layer and then this changed output feed to following layers. I used this code but I can’t replace this change to output of layer in model.


I manipulate the output of one layer and then this changed output feed to following layers. I used this code but I can’t replace this change to output of layer in model.
model.conv3.register_forward_hook(get_activation('conv3'))

x, labels = next(iter(test_loader))

a = activation['conv3']

a[9,0,1,:]=a[9,0,2,:]

a[9,0,2,:]=a[9,0,3,:]

a[9,0,3,:]=a[9,0,4,:]

activation['conv3']=a

output = model(x)

plt.subplot(1, 3, 1)

plt.imshow(output[9][0].detach().numpy(), cmap="gray") 

#print(activation['conv3'])

plt.subplot(1, 3, 2)