RuntimeError: Found dtype Long but expected Float for YOLO recreation

Hi,

I’m a 4th year CS student and as part of my engineering thesis I’m trying to recreate YOLO algorithm for object detection.

Despite making sure that both targets and inputs are converted to float and device before training I seem to experience this type of error and can’t solve it on my own.

The full source code is available in my public github repository

I believe that the problem may be relevant to the advanced loss function, but my debugging hasn’t helped.

Maybe someone could give me some tips as to how could I solve this problem?

So error you hit is in the backward. The first thing I would recommend to do for this is use the (very slow) ẁith torch.anomaly_detection() mode as it will give you the backtrace of the backward.

Best regards

Thomas

1 Like

After debugging with torch.anomaly_detection I have added .to(float) in almost all tensors in loss and it works now!
Thank You :slight_smile:

1 Like

Glad you solved it. If you stare down the backtrace (in the bottom half) to find the bit that isn’t Jupyter nor PyTorch internals but your code, the crucial information is the line with no_object_loss = LAMBDA_NOOBJ * self.mse( so likely it was not_exists_object_filter that was not float.

Unsolicited advice: If you use triple backticks (```) before and after the code in forum posts, it’ll use better formatting.

1 Like