Hello. I want to implement a custom loss function. However, I need to use output of a network as “index” of a different tensor to compute loss. For that, I use output.data.numpy()[0] to get index value as integer.(since my original code is complicated, I wrote simplified version below).
I get an error “in-place operations can be only used on variables that don’t share storage with any other variables, but detected that there are 2 objects sharing it”
Is there any other way to use output of network as index of another tensor?
ground_truth=Variable(TORCH_TENSOR)
final_output_matrix=Variable(TORCH_TENSOR)
input = Variable(TORCH_TENSOR)

output=network(input)
index=output[i][j].data.numpy()[0] # i , j : some int values
loss = abs(ground_truth[p] - final_output[index]) # p: some int values
loss.backward()