excuse me. I also encounter this problem when I run the code below in a forward() function(code is in the image). If I comment the guess_img_dist_arr[n]=(torch.norm(guess_img[y][x]-guess_img[y_co][x_co]))
It will not raise the error, but get a wrong result.
could you tell me how to fix this?
You should not modify a single Variable inplace multiple times.
In your case, one wait to solve this would be:
for i in range(k_clusters):
# some code
guess_img_dist_list = []
for n in range(length):
# some code
guess_img_dist_list.append(torch.norm(...))
guess_img_dist_arr = torch.cat(guess_img_dist_list, 0)