liorshk / facenet_pytorch

PyTorch implementation of the paper "FaceNet: A Unified Embedding for Face Recognition and Clustering"
MIT License
322 stars 90 forks source link

RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn #9

Open HiYellowC opened 5 years ago

HiYellowC commented 5 years ago

out_selected_a = Variable(torch.from_numpy(out_a.cpu().data.numpy()[hard_triplets]).cuda()) out_selected_p = Variable(torch.from_numpy(out_p.cpu().data.numpy()[hard_triplets]).cuda()) out_selected_n = Variable(torch.from_numpy(out_n.cpu().data.numpy()[hard_triplets]).cuda())

will lead to

RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

why not use:

out_selected_a = out_a[hard_triplets] out_selected_p = out_p[hard_triplets] out_selected_n = out_n[hard_triplets]