Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions utils/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ def build_targets(p, targets, model):
g = 0.5 # offset
multi_gpu = is_parallel(model)
for i, jj in enumerate(model.module.yolo_layers if multi_gpu else model.yolo_layers):
# fixes torch==1.12 compatibility (implements ultralytics/yolov5 pr #8067)
shape = p[i].shape

# get number of grid points and anchor vec for this yolo layer
anchors = model.module.module_list[jj].anchor_vec if multi_gpu else model.module_list[jj].anchor_vec
gain[2:] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain
gain[2:] = torch.tensor(shape)[[3, 2, 3, 2]] # xyxy gain

# Match targets to anchors
a, t, offsets = [], targets * gain, 0
Expand Down Expand Up @@ -164,7 +167,7 @@ def build_targets(p, targets, model):

# Append
#indices.append((b, a, gj, gi)) # image, anchor, grid indices
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1))) # image, anchor, grid indices
indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1))) # image, anchor, grid indices
tbox.append(torch.cat((gxy - gij, gwh), 1)) # box
anch.append(anchors[a]) # anchors
tcls.append(c) # class
Expand Down