Hello,
I am trying to modify a layer’s output and pass it to the next, I try to use the forward hook function but I can only read the data, not modify them, could you give me some advice? I really appreciate it!
activation = {}
def get_activation(name):
def hook(model, input, output):
activation[name] = output.detach()
return hook
model2.fc3.register_forward_hook(get_activation('fc3'))
outputs = model2(images)
print(outputs)
kc = activation['fc3']
zc=kc[:, :16]
out_feature=find_close(feature,zc,kc)
outputs = model2(images)