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

GPU tensor to int conversion bugs #148

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions run_ssd_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@

for i in range(boxes.size(0)):
box = boxes[i, :]
cv2.rectangle(orig_image, (box[0], box[1]), (box[2], box[3]), (255, 255, 0), 4)
cv2.rectangle(orig_image, (int(box[0].item()), int(box[1].item())), (int(box[2].item()), int(box[3].item())), (255, 255, 0), 4)
#label = f"""{voc_dataset.class_names[labels[i]]}: {probs[i]:.2f}"""
label = f"{class_names[labels[i]]}: {probs[i]:.2f}"
cv2.putText(orig_image, label,
(box[0] + 20, box[1] + 40),
(int(box[0].item()) + 20, int(box[1].item()) + 40),
cv2.FONT_HERSHEY_SIMPLEX,
1, # font scale
(255, 0, 255),
Expand Down
10 changes: 5 additions & 5 deletions run_ssd_live_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
if len(sys.argv) >= 5:
cap = cv2.VideoCapture(sys.argv[4]) # capture from file
else:
cap = cv2.VideoCapture(0) # capture from camera
cap.set(3, 1920)
cap.set(4, 1080)
cap = cv2.VideoCapture(2) # capture from camera
cap.set(3, 1280)
cap.set(4, 720)

class_names = [name.strip() for name in open(label_path).readlines()]
num_classes = len(class_names)
Expand Down Expand Up @@ -73,10 +73,10 @@
for i in range(boxes.size(0)):
box = boxes[i, :]
label = f"{class_names[labels[i]]}: {probs[i]:.2f}"
cv2.rectangle(orig_image, (box[0], box[1]), (box[2], box[3]), (255, 255, 0), 4)
cv2.rectangle(orig_image, (int(box[0].item()), int(box[1].item())), (int(box[2].item()), int(box[3].item())), (255, 255, 0), 4) #convert tensors into ints. Fixes "TypeError: function takes exactly 4 arguments (2 given)"

cv2.putText(orig_image, label,
(box[0]+20, box[1]+40),
(int(box[0].item())+20, int(box[1].item())+40),
cv2.FONT_HERSHEY_SIMPLEX,
1, # font scale
(255, 0, 255),
Expand Down
3 changes: 3 additions & 0 deletions vision/utils/box_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def convert_locations_to_boxes(locations, priors, center_variance,
boxes: priors: [[center_x, center_y, h, w]]. All the values
are relative to the image size.
"""
if torch.cuda.is_available():
locations = locations.cuda() #explicitly move tensor to cuda; fixes error "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!"

# priors can have one dimension less.
if priors.dim() + 1 == locations.dim():
priors = priors.unsqueeze(0)
Expand Down