Hi All,
I have calculated some weights per label for my dataset. Something like this:
 label_weights =  {0:2.0, 1:3.5, 2:0.7, 3:1.5}
Next, I want to multiply these weights with the gradient of the loss function according to the label of the input image. Will something like this work:
for x , t in train_loader:
     optimizer.zero_grad ( )
     z = network (x.to (device))
     J = loss (z , t.to (device))
     J.backward ( )
      for p in network.parameters():
           p.grad *= label_weights 
      optimizer.step ( )

Or is there another way to do it?
Thanks for your help in advance