@GuillaumeLeclerc Your answer points out the main problem with my codes.
I am trying to write code to run as following:
fm means feature map, whose shape is [batch_size, channel, height, widt]
mask means the marked mask denoting that the same instance has the same tags. Its shape is the same as fm.
`num’ mean how many instances in the corresponding sample in batch, Its shape is [batch_size].
For each sample in the batch, it is intended to pull the value of the pixel in fm with the same tag as close as possible, While pushing the value of the pixel in fm with different tags as far as possible.
I will try another way to implement this kind of function. Would you please share your solution with me if you come up with any idea to solve this problem using vectorized operation. Thanks