I’m new in PyTorch. I am trying to write a function that adds some arbitrary Gaussian noise to the wights during the training process. my code is like this

for m in model.modules():
if hasattr(m, ‘weight’):
m.weight.add_(np.random.normal(my_mean, my_std, m.shape)*noise_strength)
and my question is the shape of “m” how can I create noise with its shape?
I’m confused how should I do that, any help would be appreciated.

class TripletNet(nn.Module):
def init(self, embedding_net):
super(TripletNet, self).init()
self.embedding_net = embedding_net
embedding_net = EmbeddingNet()
model = TripletNet(embedding_net)

So, I am using define some arbitrary mean and std then use them into make Gaussian noise how can i add this noise during the training process of this network in each epoch. because in each epoch i define a new mean and std.

hi Ravin Jain, thanks for your good comment. I have a question about your code:
x.weigh.data.add_(t) or x.weight.add_(t) what is the difference between of them and which is correct?