0
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_29802/2631177067.py in <module>
      7 #         print('gambar0: ', img0)
      8 #         print('gambar1: ', img1)
----> 9 loss_contrastive = criterion(output1,output2,label)
     10 loss_contrastive.backward()
     11 optimizer.step()

~/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/nn/modules/module.py

在 _call_impl(self, *input, **kwargs) 1100 如果不是 (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks 1101 or _global_forward_hooks or _global_forward_pre_hooks): -> 1102 return forward_call(*input, **kwargs) 1103 # 使用jit时不要调用函数 1104 full_backward_hooks, non_full_backward_hooks = [], []

/tmp/ipykernel_29802/4271192651.py in forward(self, output1, output2, label)
     11     def forward(self, output1, output2, label):
     12         euclidean_distance = F.pairwise_distance(output1, output2, keepdim = True)
---> 13         loss_contrastive = torch.mean((1-label) * torch.pow(euclidean_distance, 2) +
     14                                       (label) * torch.pow(torch.clamp(self.margin - euclidean_distance, min=0.0), 2))
     15
4

0 回答 0