Skip to content

Commit 4dcdc63

Browse files
authored
Merge pull request #117 from dzenanz/boxVis
Allow visualization of bounding boxes
2 parents bad4500 + 2c6c569 commit 4dcdc63

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def hook(layer):
951951

952952
return hook
953953

954-
def vis_image(imgs, pred_masks, gt_masks, save_path, reverse = False, points = None):
954+
def vis_image(imgs, pred_masks, gt_masks, save_path, reverse = False, points = None, boxes = None):
955955

956956
b,c,h,w = pred_masks.size()
957957
dev = pred_masks.get_device()
@@ -997,6 +997,16 @@ def vis_image(imgs, pred_masks, gt_masks, save_path, reverse = False, points = N
997997
gt_masks[i,0,p[i,0]-5:p[i,0]+5,p[i,1]-5:p[i,1]+5] = 0.5
998998
gt_masks[i,1,p[i,0]-5:p[i,0]+5,p[i,1]-5:p[i,1]+5] = 0.1
999999
gt_masks[i,2,p[i,0]-5:p[i,0]+5,p[i,1]-5:p[i,1]+5] = 0.4
1000+
if boxes is not None:
1001+
for i in range(b):
1002+
# the next line causes: ValueError: Tensor uint8 expected, got torch.float32
1003+
# imgs[i, :] = torchvision.utils.draw_bounding_boxes(imgs[i, :], boxes[i])
1004+
# until TorchVision 0.19 is released (paired with Pytorch 2.4), apply this workaround:
1005+
img255 = (imgs[i] * 255).byte()
1006+
img255 = torchvision.utils.draw_bounding_boxes(img255, boxes[i].reshape(-1, 4), colors="red")
1007+
img01 = img255 / 255
1008+
# torchvision.utils.save_image(img01, save_path + "_boxes.png")
1009+
imgs[i, :] = img01
10001010
tup = (imgs[:row_num,:,:,:],pred_masks[:row_num,:,:,:], gt_masks[:row_num,:,:,:])
10011011
# compose = torch.cat((imgs[:row_num,:,:,:],pred_disc[:row_num,:,:,:], pred_cup[:row_num,:,:,:], gt_disc[:row_num,:,:,:], gt_cup[:row_num,:,:,:]),0)
10021012
compose = torch.cat(tup,0)

0 commit comments

Comments
 (0)