Hello everyone.
Let A be a tensor of shape 64*10. Each row corresponds to the output of our model on a single image and we know the ground label of all images. I want to multiply each row by weight according to its label. For example, I want to multiply all rows with labels 1 by 1.5, all rows with labels 2 by 0.25, and so on. Finally, I want a tensor with the same shape 64*10.
What is vectorized efficient way to do this in PyTorch. Thanks a lot.
Generate your weighted vector of shape 1x10, and then multiply it element-wise with your label tensor. Multiply then the result by the output of your model.
Maybe I didn’t express my question well; I think there is something wrong. When I print “labels * weighted_mask”, the weights are multiplied by the label number. This is not what I wanted. Suppose the first row was [1, 0.5, 2, 1.5] and its label was 2. I want to multiply all rows with labels 2 by 5. So this row should be [5, 2.5, 10, 7.5].