liuruijin17 / LSTR

This is an official repository of End-to-end Lane Shape Prediction with Transformers.
BSD 3-Clause "New" or "Revised" License
647 stars 130 forks source link

Something wrong with the CE loss? #50

Closed lhwcv closed 3 years ago

lhwcv commented 3 years ago

Hi, In dataset: lanes[lane_pos, 0] = category #which is 1 in the code

While in loss_label, target_classes is all 1 when self.num_classes==1

...
target_classes = torch.full(src_logits.shape[:2], self.num_classes, dtype=torch.int64, device=src_logits.device)
target_classes[idx] = target_classes_o
loss_ce = F.cross_entropy(src_logits.transpose(1, 2), target_classes, self.empty_weight)

!!! loss_ce can be alway 0 there. Thanks for your work, wish a reply

liuruijin17 commented 3 years ago

Hi, correct, actually the target_classes is initialized as an all 'background class' tensor, so if self.num_classes == 1, the target_classes would be all 1, which would be confused for the network since the 'lane class' is set as 1.

If self.num_classes == 1, then target_classes should not be initialized by 'torch.full'. E.g., initializing target_classes by torch.ones + 1

Just make sure target_classes is not initialized as an all "lane class" vector.

lhwcv commented 3 years ago

Thanks a lot!