in detic/modeling/debug.py [0:0]
def debug_train(
images, gt_instances, flattened_hms, reg_targets, labels, pos_inds,
shapes_per_level, locations, strides):
'''
images: N x 3 x H x W
flattened_hms: LNHiWi x C
shapes_per_level: L x 2 [(H_i, W_i)]
locations: LNHiWi x 2
'''
reg_inds = torch.nonzero(
reg_targets.max(dim=1)[0] > 0).squeeze(1)
N = len(images)
images = _imagelist_to_tensor(images)
repeated_locations = [torch.cat([loc] * N, dim=0) \
for loc in locations]
locations = torch.cat(repeated_locations, dim=0)
gt_hms = _decompose_level(flattened_hms, shapes_per_level, N)
masks = flattened_hms.new_zeros((flattened_hms.shape[0], 1))
masks[pos_inds] = 1
masks = _decompose_level(masks, shapes_per_level, N)
for i in range(len(images)):
image = images[i].detach().cpu().numpy().transpose(1, 2, 0)
color_maps = []
for l in range(len(gt_hms)):
color_map = _get_color_image(
gt_hms[l][i].detach().cpu().numpy())
color_maps.append(color_map)
cv2.imshow('gthm_{}'.format(l), color_map)
blend = _blend_image_heatmaps(image.copy(), color_maps)
if gt_instances is not None:
bboxes = gt_instances[i].gt_boxes.tensor
for j in range(len(bboxes)):
bbox = bboxes[j]
cv2.rectangle(
blend,
(int(bbox[0]), int(bbox[1])),
(int(bbox[2]), int(bbox[3])),
(0, 0, 255), 3, cv2.LINE_AA)
for j in range(len(pos_inds)):
image_id, l = _ind2il(pos_inds[j], shapes_per_level, N)
if image_id != i:
continue
loc = locations[pos_inds[j]]
cv2.drawMarker(
blend, (int(loc[0]), int(loc[1])), (0, 255, 255),
markerSize=(l + 1) * 16)
for j in range(len(reg_inds)):
image_id, l = _ind2il(reg_inds[j], shapes_per_level, N)
if image_id != i:
continue
ltrb = reg_targets[reg_inds[j]]
ltrb *= strides[l]
loc = locations[reg_inds[j]]
bbox = [(loc[0] - ltrb[0]), (loc[1] - ltrb[1]),
(loc[0] + ltrb[2]), (loc[1] + ltrb[3])]
cv2.rectangle(
blend,
(int(bbox[0]), int(bbox[1])),
(int(bbox[2]), int(bbox[3])),
(255, 0, 0), 1, cv2.LINE_AA)
cv2.circle(blend, (int(loc[0]), int(loc[1])), 2, (255, 0, 0), -1)
cv2.imshow('blend', blend)
cv2.waitKey()