yangze0930 / NTS-Net

This is a PyTorch implementation of the ECCV2018 paper "Learning to Navigate for Fine-grained Classification" (Ze Yang, Tiange Luo, Dong Wang, Zhiqiang Hu, Jun Gao, Liwei Wang).
MIT License
452 stars 118 forks source link

List Loss error, IndexError: index 4 is out of bounds for dimension 0 with size 4 #21

Closed muellerzr closed 5 years ago

muellerzr commented 5 years ago

When I run the model, I get IndexError: index 4 is out of bounds for dimension 0 with size 4. The stack trace points to:


     15     raw_logits, concat_logits, part_logits, _, top_n_prob = net(img)
     16     part_loss = list_loss(part_logits.view(batch_size * PROPOSAL_NUM, -1),
---> 17                                label.unsqueeze(1).repeat(1, PROPOSAL_NUM).view(-1)).view(batch_size, PROPOSAL_NUM)
     18     raw_loss = creterion(raw_logits, label)
     19     concat_loss = creterion(concat_logits, label)

.........................................................................................................................
     84 def list_loss(logits, targets):
     85     temp = F.log_softmax(logits, -1)
---> 86     loss = [-temp[i][targets[i].item()] for i in range(logits.size(0))]
     87     return torch.stack(loss)```
Totoro-wen commented 5 years ago

Hello, how did you solve this problem!

muellerzr commented 5 years ago

I do not remember as it was months ago. But my fork Is https://github.com/muellerzr/fastai_nts_net/blob/master/loss_functions.py

Perhaps that can help! :)

Totoro-wen commented 5 years ago

I do not remember as it was months ago. But my fork Is https://github.com/muellerzr/fastai_nts_net/blob/master/loss_functions.py

Perhaps that can help! :)

Thanks!