Hello,
I want to input some normal noise into part of tensor of some inner layer, for example, I have hooked the first 16 of a layer tensor, How could I add the noise?
I notice
class AddGaussianNoise(object):
def init(self, mean=0., std=1.):
self.std = std
self.mean = mean
I’m unsure what “inner layer” means in your context, but in case you want to add noise to an intermediate activation you could write AddGaussianNoise as an nn.Module and apply it in the forward pass or you could also add the noise directly to the activation in the forward method.
sorry for my expression, The inner layer what I want to mean is, for example, I have 5 layers NN, and I hook out the least second layer, in this layer I have a total of 200 nodes, and I only want to add noise to the first 16 nodes. Based on this situation, could you help me out? Thank you so much!
I’m not sure what “nodes” refer to, but in case it’s the output activation, you could use the previously suggested method of adding the noise directly to the output in the forward method.