|
@@ -784,6 +784,7 @@ def lines_point_pair_loss(line_logits, proposals, gt_lines, line_matched_idxs):
|
|
|
def compute_arc_loss(feature_logits, proposals, gt_, pos_matched_idxs):
|
|
def compute_arc_loss(feature_logits, proposals, gt_, pos_matched_idxs):
|
|
|
print(f'compute_arc_loss:{feature_logits.shape}')
|
|
print(f'compute_arc_loss:{feature_logits.shape}')
|
|
|
N, K, H, W = feature_logits.shape
|
|
N, K, H, W = feature_logits.shape
|
|
|
|
|
+
|
|
|
len_proposals = len(proposals)
|
|
len_proposals = len(proposals)
|
|
|
|
|
|
|
|
empty_count = 0
|
|
empty_count = 0
|
|
@@ -808,6 +809,7 @@ def compute_arc_loss(feature_logits, proposals, gt_, pos_matched_idxs):
|
|
|
|
|
|
|
|
gs_heatmaps = []
|
|
gs_heatmaps = []
|
|
|
# print(f'point_matched_idxs:{point_matched_idxs}')
|
|
# print(f'point_matched_idxs:{point_matched_idxs}')
|
|
|
|
|
+ print(f'gt_masks:{gt_[0].shape}')
|
|
|
for proposals_per_image, gt_kp_in_image, midx in zip(proposals, gt_, pos_matched_idxs):
|
|
for proposals_per_image, gt_kp_in_image, midx in zip(proposals, gt_, pos_matched_idxs):
|
|
|
# [
|
|
# [
|
|
|
# (Tensor(38, 4), Tensor(1, 57, 2), Tensor(38, 1)),
|
|
# (Tensor(38, 4), Tensor(1, 57, 2), Tensor(38, 1)),
|
|
@@ -815,8 +817,12 @@ def compute_arc_loss(feature_logits, proposals, gt_, pos_matched_idxs):
|
|
|
# ]
|
|
# ]
|
|
|
print(f'proposals_per_image:{proposals_per_image.shape}')
|
|
print(f'proposals_per_image:{proposals_per_image.shape}')
|
|
|
kp = gt_kp_in_image[midx]
|
|
kp = gt_kp_in_image[midx]
|
|
|
- # print(f'gt_kp_in_image:{gt_kp_in_image}')
|
|
|
|
|
|
|
+ t_h, t_w = kp.shape[-2:]
|
|
|
|
|
+ print(f't_h:{t_h}, t_w:{t_w}')
|
|
|
|
|
+
|
|
|
|
|
+ print(f'gt_kp_in_image:{gt_kp_in_image.shape}')
|
|
|
if proposals_per_image.shape[0] > 0 and gt_kp_in_image.shape[0] > 0:
|
|
if proposals_per_image.shape[0] > 0 and gt_kp_in_image.shape[0] > 0:
|
|
|
|
|
+
|
|
|
gs_heatmaps_per_img = arc_points_to_heatmap(kp, proposals_per_image, discretization_size)
|
|
gs_heatmaps_per_img = arc_points_to_heatmap(kp, proposals_per_image, discretization_size)
|
|
|
gs_heatmaps.append(gs_heatmaps_per_img)
|
|
gs_heatmaps.append(gs_heatmaps_per_img)
|
|
|
|
|
|
|
@@ -839,23 +845,31 @@ def compute_arc_loss(feature_logits, proposals, gt_, pos_matched_idxs):
|
|
|
|
|
|
|
|
return line_loss
|
|
return line_loss
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def arc_points_to_heatmap(keypoints, rois, heatmap_size):
|
|
def arc_points_to_heatmap(keypoints, rois, heatmap_size):
|
|
|
print(f'rois:{rois.shape}')
|
|
print(f'rois:{rois.shape}')
|
|
|
print(f'heatmap_size:{heatmap_size}')
|
|
print(f'heatmap_size:{heatmap_size}')
|
|
|
|
|
|
|
|
print(f'keypoints.shape:{keypoints.shape}')
|
|
print(f'keypoints.shape:{keypoints.shape}')
|
|
|
# batch_size, num_keypoints, _ = keypoints.shape
|
|
# batch_size, num_keypoints, _ = keypoints.shape
|
|
|
|
|
+ t_h, t_w = keypoints.shape[-2:]
|
|
|
|
|
+ scale=heatmap_size/t_w
|
|
|
|
|
+ print(f'scale:{scale}')
|
|
|
|
|
+ x = keypoints[..., 0]*scale
|
|
|
|
|
+ y = keypoints[..., 1]*scale
|
|
|
|
|
+
|
|
|
|
|
+ x = x.unsqueeze(1)
|
|
|
|
|
+ y = y.unsqueeze(1)
|
|
|
|
|
|
|
|
- x = keypoints[..., 0].unsqueeze(1)
|
|
|
|
|
- y = keypoints[..., 1].unsqueeze(1)
|
|
|
|
|
num_points=x.shape[2]
|
|
num_points=x.shape[2]
|
|
|
print(f'num_points:{num_points}')
|
|
print(f'num_points:{num_points}')
|
|
|
- gs = generate_mask_gaussian_heatmaps(x, y, num_points=num_points, heatmap_size=heatmap_size, sigma=2.0)
|
|
|
|
|
|
|
+ gs = generate_mask_gaussian_heatmaps(x, y, num_points=num_points, heatmap_size=heatmap_size, sigma=10)
|
|
|
|
|
+ print(f'gs max :{gs.max()},gs.shape:{gs.shape}')
|
|
|
# show_heatmap(gs[0],'target')
|
|
# show_heatmap(gs[0],'target')
|
|
|
all_roi_heatmap = []
|
|
all_roi_heatmap = []
|
|
|
for roi, heatmap in zip(rois, gs):
|
|
for roi, heatmap in zip(rois, gs):
|
|
|
- # show_heatmap(heatmap, 'target')
|
|
|
|
|
- print(f'heatmap:{heatmap.shape}')
|
|
|
|
|
|
|
+ show_heatmap(heatmap, 'target')
|
|
|
|
|
+ print(f'heatmap.shape:{heatmap.shape}')
|
|
|
heatmap = heatmap.unsqueeze(0)
|
|
heatmap = heatmap.unsqueeze(0)
|
|
|
x1, y1, x2, y2 = map(int, roi)
|
|
x1, y1, x2, y2 = map(int, roi)
|
|
|
roi_heatmap = torch.zeros_like(heatmap)
|
|
roi_heatmap = torch.zeros_like(heatmap)
|
|
@@ -1182,7 +1196,10 @@ def arc_inference(x, arc_boxes,th):
|
|
|
|
|
|
|
|
import torch.nn.functional as F
|
|
import torch.nn.functional as F
|
|
|
|
|
|
|
|
-def heatmaps_to_arc(maps, rois, threshold=0.1, output_size=(128, 128)):
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def heatmaps_to_arc(maps, rois, threshold=0, output_size=(128, 128)):
|
|
|
"""
|
|
"""
|
|
|
Args:
|
|
Args:
|
|
|
maps: [N, 3, H, W] - full heatmaps
|
|
maps: [N, 3, H, W] - full heatmaps
|
|
@@ -1233,7 +1250,7 @@ def heatmaps_to_arc(maps, rois, threshold=0.1, output_size=(128, 128)):
|
|
|
|
|
|
|
|
# NMS + threshold
|
|
# NMS + threshold
|
|
|
nms_roi = non_maximum_suppression(roi_map_resized) # shape: [1, H, W]
|
|
nms_roi = non_maximum_suppression(roi_map_resized) # shape: [1, H, W]
|
|
|
- bin_mask = (nms_roi > threshold).float() # shape: [1, H, W]
|
|
|
|
|
|
|
+ bin_mask = (nms_roi >= threshold).float() # shape: [1, H, W]
|
|
|
print(f" bin_mask.sum(): {bin_mask.sum().item()}")
|
|
print(f" bin_mask.sum(): {bin_mask.sum().item()}")
|
|
|
|
|
|
|
|
# resize back to original roi size
|
|
# resize back to original roi size
|
|
@@ -1254,6 +1271,13 @@ def heatmaps_to_arc(maps, rois, threshold=0.1, output_size=(128, 128)):
|
|
|
masks[i, 0, y1:y2, x1:x2] = bin_mask_original_size.squeeze()
|
|
masks[i, 0, y1:y2, x1:x2] = bin_mask_original_size.squeeze()
|
|
|
scores[i] = bin_mask_original_size.sum()
|
|
scores[i] = bin_mask_original_size.sum()
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # plt.figure(figsize=(6, 6))
|
|
|
|
|
+ # plt.imshow(masks[i, 0].cpu().numpy(), cmap='gray')
|
|
|
|
|
+ # plt.title(f"Mask {i}, score={scores[i].item():.1f}")
|
|
|
|
|
+ # plt.axis('off')
|
|
|
|
|
+ # plt.show()
|
|
|
|
|
+
|
|
|
print(f" bin_mask_original_size.shape: {bin_mask_original_size.shape}, sum: {scores[i].item()}")
|
|
print(f" bin_mask_original_size.shape: {bin_mask_original_size.shape}, sum: {scores[i].item()}")
|
|
|
|
|
|
|
|
print(f"==> Done. Total valid masks: {(scores > 0).sum().item()} / {N}")
|
|
print(f"==> Done. Total valid masks: {(scores > 0).sum().item()} / {N}")
|