WongKinYiu / yolor

implementation of paper - You Only Learn One Representation: Unified Network for Multiple Tasks (https://arxiv.org/abs/2105.04206)
GNU General Public License v3.0
1.98k stars 524 forks source link

fix: RuntimeError: result type Float can't be cast to the desired output type long int #271

Open ItzDerock opened 1 year ago

ItzDerock commented 1 year ago

This PR re-implements the patch done in ultralytics/yolov5 pr 8067 to fix this error when using torch 1.12

ItzDerock commented 1 year ago

fixes #270

RainYQ commented 1 year ago

for torch == 1.13.0

just fix it

utils/loss.py

-> 130 gain = torch.ones(6, device=targets.device, dtype=torch.long) # normalized to gridspace gain -> 138 gain[2:] = torch.tensor(p[i].shape, dtype=torch.long)[[3, 2, 3, 2]] # xyxy gain -> 144 at = torch.arange(na, device=targets.device).view(na, 1).repeat(1, nt) # anchor tensor, same as .repeat_interleave(nt)