SysCV / transfiner

Mask Transfiner for High-Quality Instance Segmentation, CVPR 2022
https://www.vis.xyz/pub/transfiner
Apache License 2.0
534 stars 61 forks source link

RuntimeError: torch.nn.functional.binary_cross_entropy and torch.nn.BCELoss are unsafe to autocast #43

Closed Hubert2102 closed 2 years ago

Hubert2102 commented 2 years ago

File "/export/software/anacondamini/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/export/segment/transfiner/detectron2/modeling/roi_heads/mask_head.py", line 537, in forward x, x_uncertain, x_bo, x_hr, x_hr_l, x_hr_ll, x_c, x_p2_s, encoder, instances, self.vis_period) File "/export/segment/transfiner/detectron2/modeling/roi_heads/mask_head.py", line 296, in mask_rcnn_loss pred_mask_logits_uncertain, gt_masks_uncertain, pred_mask_logits_uncertain.shape[0]) + F.binary_cross_entropy(pred_mask_logits_uncertain, gt_masks_uncertain, reduction="mean") File "/export/software/anacondamini/lib/python3.7/site-packages/torch/nn/functional.py", line 2526, in binary_cross_entropy input, target, weight, reduction_enum)

RuntimeError: torch.nn.functional.binary_cross_entropy and torch.nn.BCELoss are unsafe to autocast. Many models use a sigmoid layer right before the binary cross entropy layer. In this case, combine the two layers using torch.nn.functional.binary_cross_entropy_with_logits or torch.nn.BCEWithLogitsLoss. binary_cross_entropy_with_logits and BCEWithLogits are safe to autocast.

Hubert2102 commented 2 years ago

how to solve it?thanks

lkeab commented 2 years ago

you can refer to the solution here. or update your pytorch version to 1.7.1.