|
|
@@ -1251,13 +1251,7 @@ class RoIHeads(nn.Module):
|
|
|
h, w = targets[0]["img_size"]
|
|
|
img_size = h
|
|
|
|
|
|
- # gt_arcs_tensor = torch.zeros(0, 0)
|
|
|
- # if len(gt_arcs) > 0:
|
|
|
- # gt_arcs_tensor = torch.cat(gt_arcs)
|
|
|
- # print(f'gt_arcs_tensor:{gt_arcs_tensor.shape}')
|
|
|
- #
|
|
|
- # if gt_arcs_tensor.shape[0] > 0:
|
|
|
- # print(f'start to compute point_loss')
|
|
|
+
|
|
|
if len(gt_arcs) > 0 and feature_logits is not None:
|
|
|
loss_arc = compute_ins_loss(feature_logits, arc_proposals, gt_arcs, arc_pos_matched_idxs)
|
|
|
|
|
|
@@ -1277,13 +1271,7 @@ class RoIHeads(nn.Module):
|
|
|
h, w = targets[0]["img_size"]
|
|
|
img_size = h
|
|
|
|
|
|
- # gt_arcs_tensor = torch.zeros(0, 0)
|
|
|
- # if len(gt_arcs) > 0:
|
|
|
- # gt_arcs_tensor = torch.cat(gt_arcs)
|
|
|
- # print(f'gt_arcs_tensor:{gt_arcs_tensor.shape}')
|
|
|
|
|
|
- # if gt_arcs_tensor.shape[0] > 0 and feature_logits is not None:
|
|
|
- # print(f'start to compute arc_loss')
|
|
|
|
|
|
if len(gt_arcs) > 0 and feature_logits is not None:
|
|
|
print(f'start to compute arc_loss')
|
|
|
@@ -1341,9 +1329,26 @@ class RoIHeads(nn.Module):
|
|
|
if matched_idxs is None:
|
|
|
raise ValueError("if in trainning, matched_idxs should not be None")
|
|
|
for img_id in range(num_images):
|
|
|
+
|
|
|
+ # circle_pos = torch.where(labels[img_id] == 4)[0]
|
|
|
+ # ins_proposals.append(proposals[img_id][circle_pos])
|
|
|
+ # ins_pos_matched_idxs.append(matched_idxs[img_id][circle_pos])
|
|
|
circle_pos = torch.where(labels[img_id] == 4)[0]
|
|
|
- ins_proposals.append(proposals[img_id][circle_pos])
|
|
|
- ins_pos_matched_idxs.append(matched_idxs[img_id][circle_pos])
|
|
|
+ circle_pos = circle_pos.flatten()
|
|
|
+ idxs = circle_pos.detach().cpu().tolist()
|
|
|
+ num_prop = len(proposals[img_id])
|
|
|
+ for idx in idxs:
|
|
|
+ if idx < 0 or idx >= num_prop:
|
|
|
+ raise RuntimeError(
|
|
|
+ f"Index out of bounds: circle_pos={idx}, but proposals len={num_prop}, "
|
|
|
+ f"img_id={img_id}"
|
|
|
+ )
|
|
|
+ ins_proposals.append(
|
|
|
+ proposals[img_id][idxs]
|
|
|
+ )
|
|
|
+ ins_pos_matched_idxs.append(
|
|
|
+ matched_idxs[img_id][idxs]
|
|
|
+ )
|
|
|
else:
|
|
|
if targets is not None:
|
|
|
|
|
|
@@ -1356,9 +1361,25 @@ class RoIHeads(nn.Module):
|
|
|
raise ValueError("if in trainning, matched_idxs should not be None")
|
|
|
|
|
|
for img_id in range(num_images):
|
|
|
+ # circle_pos = torch.where(labels[img_id] == 4)[0]
|
|
|
+ # ins_proposals.append(proposals[img_id][circle_pos])
|
|
|
+ # ins_pos_matched_idxs.append(matched_idxs[img_id][circle_pos])
|
|
|
circle_pos = torch.where(labels[img_id] == 4)[0]
|
|
|
- ins_proposals.append(proposals[img_id][circle_pos])
|
|
|
- ins_pos_matched_idxs.append(matched_idxs[img_id][circle_pos])
|
|
|
+ circle_pos = circle_pos.flatten()
|
|
|
+ idxs = circle_pos.detach().cpu().tolist()
|
|
|
+ num_prop = len(proposals[img_id])
|
|
|
+ for idx in idxs:
|
|
|
+ if idx < 0 or idx >= num_prop:
|
|
|
+ raise RuntimeError(
|
|
|
+ f"Index out of bounds: circle_pos={idx}, but proposals len={num_prop}, "
|
|
|
+ f"img_id={img_id}"
|
|
|
+ )
|
|
|
+ ins_proposals.append(
|
|
|
+ proposals[img_id][idxs]
|
|
|
+ )
|
|
|
+ ins_pos_matched_idxs.append(
|
|
|
+ matched_idxs[img_id][idxs]
|
|
|
+ )
|
|
|
|
|
|
else:
|
|
|
pos_matched_idxs = None
|
|
|
@@ -1375,7 +1396,7 @@ class RoIHeads(nn.Module):
|
|
|
print(f'features from backbone:{features['0'].shape}')
|
|
|
feature_logits = self.ins_forward1(features, image_shapes, ins_proposals)
|
|
|
|
|
|
- arc_equation = self.arc_equation_head(feature_logits) # [proposal和,7]
|
|
|
+ # arc_equation = self.arc_equation_head(feature_logits) # [proposal和,7]
|
|
|
|
|
|
loss_ins = None
|
|
|
loss_ins_extra=None
|
|
|
@@ -1409,12 +1430,7 @@ class RoIHeads(nn.Module):
|
|
|
print(f'start to compute circle_loss')
|
|
|
|
|
|
loss_ins = compute_ins_loss(feature_logits, ins_proposals, gt_inses,ins_pos_matched_idxs)
|
|
|
- total_loss, loss_arc_equation, loss_arc_ends = compute_arc_equation_loss(arc_equation,
|
|
|
- ins_proposals,
|
|
|
- gt_mask_ends,
|
|
|
- gt_mask_params,
|
|
|
- ins_pos_matched_idxs,
|
|
|
- labels)
|
|
|
+ # total_loss, loss_arc_equation, loss_arc_ends = compute_arc_equation_loss(arc_equation,ins_proposals,gt_mask_params,ins_pos_matched_idxs,labels)
|
|
|
loss_arc_ends = loss_arc_ends
|
|
|
if loss_arc_equation is None:
|
|
|
print(f'loss_arc_equation is None')
|
|
|
@@ -1456,8 +1472,8 @@ class RoIHeads(nn.Module):
|
|
|
|
|
|
loss_ins = compute_ins_loss(feature_logits, ins_proposals, gt_inses,
|
|
|
ins_pos_matched_idxs)
|
|
|
- total_loss, loss_arc_equation, loss_arc_ends = compute_arc_equation_loss(
|
|
|
- arc_equation, ins_proposals, gt_mask_ends, gt_mask_params, ins_pos_matched_idxs, labels)
|
|
|
+ # total_loss, loss_arc_equation, loss_arc_ends = compute_arc_equation_loss(arc_equation,ins_proposals,gt_mask_params,ins_pos_matched_idxs,labels)
|
|
|
+
|
|
|
loss_arc_ends = loss_arc_ends
|
|
|
|
|
|
# loss_ins_extra = compute_circle_extra_losses(feature_logits, circle_proposals, gt_circles,circle_pos_matched_idxs)
|
|
|
@@ -1508,10 +1524,10 @@ class RoIHeads(nn.Module):
|
|
|
ins_masks, ins_scores, circle_points = ins_inference(feature_logits,
|
|
|
ins_proposals, th=0)
|
|
|
|
|
|
- arc7, arc_scores = arc_inference1(arc_equation, feature_logits, ins_proposals, 0.5)
|
|
|
- for arc_, arc_score, r in zip(arc7, arc_scores, result):
|
|
|
- r["arcs"] = arc_
|
|
|
- r["arc_scores"] = arc_score
|
|
|
+ # arc7, arc_scores = arc_inference1(arc_equation, feature_logits, ins_proposals, 0.5)
|
|
|
+ # for arc_, arc_score, r in zip(arc7, arc_scores, result):
|
|
|
+ # r["arcs"] = arc_
|
|
|
+ # r["arc_scores"] = arc_score
|
|
|
# print(f'circles_probs:{circles_probs.shape}, circles_scores:{circles_scores.shape}')
|
|
|
proposals_per_image = [box.size(0) for box in ins_proposals]
|
|
|
print(f'ins_proposals_per_image:{proposals_per_image}')
|