|
|
@@ -1395,8 +1395,12 @@ class RoIHeads(nn.Module):
|
|
|
|
|
|
print(f'features from backbone:{features['0'].shape}')
|
|
|
feature_logits = self.ins_forward1(features, image_shapes, ins_proposals)
|
|
|
+ # ins_masks, ins_scores, circle_points = ins_inference(feature_logits,
|
|
|
+ # ins_proposals, th=0)
|
|
|
|
|
|
- # 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
|
|
|
@@ -1430,7 +1434,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_params,ins_pos_matched_idxs,labels)
|
|
|
+ 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)
|
|
|
loss_arc_ends = loss_arc_ends
|
|
|
if loss_arc_equation is None:
|
|
|
print(f'loss_arc_equation is None')
|
|
|
@@ -1472,7 +1476,7 @@ 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_params,ins_pos_matched_idxs,labels)
|
|
|
+ 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)
|
|
|
|
|
|
loss_arc_ends = loss_arc_ends
|
|
|
|
|
|
@@ -1524,10 +1528,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}')
|
|
|
@@ -1815,31 +1819,31 @@ def compute_arc_equation_loss(arc_equation, proposals, gt_mask_ends, gt_mask_par
|
|
|
f'compute_arc_equation_loss line_logits.shape:{arc_equation.shape},len_proposals:{len_proposals},line_matched_idxs:{arc_pos_matched_idxs}')
|
|
|
print(f'gt_mask_ends:{gt_mask_ends}, gt_mask_params:{gt_mask_params}')
|
|
|
|
|
|
- gt_angles = []
|
|
|
- # for gt_mask_end,gt_mask_param in zip(gt_mask_ends, gt_mask_params):
|
|
|
- # print(f'gt_mask_end:{gt_mask_end}, gt_mask_param:{gt_mask_param}')
|
|
|
- # gt_angles.append(compute_arc_angles(gt_mask_end,gt_mask_param))
|
|
|
- for i in range(len(gt_mask_ends)):
|
|
|
- print(f'gt_mask_end:{gt_mask_ends[i]}, gt_mask_param:{gt_mask_params[i]}')
|
|
|
- gt_angles.append(compute_arc_angles(gt_mask_ends[i], gt_mask_params[i]))
|
|
|
+ # gt_angles = []
|
|
|
+ # # for gt_mask_end,gt_mask_param in zip(gt_mask_ends, gt_mask_params):
|
|
|
+ # # print(f'gt_mask_end:{gt_mask_end}, gt_mask_param:{gt_mask_param}')
|
|
|
+ # # gt_angles.append(compute_arc_angles(gt_mask_end,gt_mask_param))
|
|
|
+ # for i in range(len(gt_mask_ends)):
|
|
|
+ # print(f'gt_mask_end:{gt_mask_ends[i]}, gt_mask_param:{gt_mask_params[i]}')
|
|
|
+ # gt_angles.append(compute_arc_angles(gt_mask_ends[i], gt_mask_params[i]))
|
|
|
|
|
|
- print(f'gt_angles:{gt_angles}')
|
|
|
+ # print(f'gt_angles:{gt_angles}')
|
|
|
print(f'gt_mask_params:{gt_mask_params}')
|
|
|
print(f'gt_labels_all:{gt_labels_all}')
|
|
|
print(f'arc_pos_matched_idxs:{arc_pos_matched_idxs}')
|
|
|
|
|
|
gt_sel_params = []
|
|
|
gt_sel_angles = []
|
|
|
- for proposals_per_image, gt_angle, gt_params, gt_label, midx in zip(proposals, gt_angles, gt_mask_params,
|
|
|
+ for proposals_per_image, gt_ends, gt_params, gt_label, midx in zip(proposals, gt_mask_ends, gt_mask_params,
|
|
|
gt_labels_all, arc_pos_matched_idxs):
|
|
|
print(f'line_proposals_per_image:{proposals_per_image.shape}')
|
|
|
# gt_angle = torch.tensor(gt_angle)
|
|
|
- gt_angle = torch.stack(gt_angle, dim=0)
|
|
|
+ gt_ends = torch.tensor(gt_ends)
|
|
|
gt_params = torch.tensor(gt_params)
|
|
|
- if gt_angle.shape[0] > 0:
|
|
|
+ if gt_ends.shape[0] > 0:
|
|
|
# positions = (gt_label == 3).nonzero()[0].item()
|
|
|
|
|
|
- po = gt_angle[midx.cpu()]
|
|
|
+ po = gt_ends[midx.cpu()]
|
|
|
pa = gt_params[midx.cpu()]
|
|
|
print(f'po:{po},pa:{pa}')
|
|
|
|
|
|
@@ -1850,34 +1854,40 @@ def compute_arc_equation_loss(arc_equation, proposals, gt_mask_ends, gt_mask_par
|
|
|
|
|
|
gt_sel_angles = torch.cat(gt_sel_angles, dim=0)
|
|
|
gt_sel_params = torch.cat(gt_sel_params, dim=0)
|
|
|
- pred_angles = arc_equation[:, 5:7]
|
|
|
+ pred_ends = arc_equation[:, 5:9]
|
|
|
pred_params = arc_equation[:, :5]
|
|
|
|
|
|
- print_params(pred_angles, pred_params, gt_sel_angles, gt_sel_params)
|
|
|
+ # print_params(pred_angles, pred_params, gt_sel_angles, gt_sel_params)
|
|
|
|
|
|
- pred_sin = torch.sin(pred_angles)
|
|
|
- pred_cos = torch.cos(pred_angles)
|
|
|
- gt_sin = torch.sin(gt_sel_angles)
|
|
|
- gt_cos = torch.cos(gt_sel_angles)
|
|
|
- angle_loss = F.mse_loss(pred_sin, gt_sin) + F.mse_loss(pred_cos, gt_cos)
|
|
|
+ # pred_sin = torch.sin(pred_angles)
|
|
|
+ # pred_cos = torch.cos(pred_angles)
|
|
|
+ # gt_sin = torch.sin(gt_sel_angles)
|
|
|
+ # gt_cos = torch.cos(gt_sel_angles)
|
|
|
+ # angle_loss = F.mse_loss(pred_sin, gt_sin) + F.mse_loss(pred_cos, gt_cos)
|
|
|
|
|
|
|
|
|
param_loss = F.mse_loss(pred_params, gt_sel_params) / 10000
|
|
|
+ print("start")
|
|
|
+ print_params(pred_ends, gt_sel_angles)
|
|
|
+ pred_ends = pred_ends.view(-1, 2, 2)
|
|
|
+ print("end")
|
|
|
+ print_params(pred_ends, gt_sel_angles)
|
|
|
+ ends_loss = F.mse_loss(pred_ends, gt_sel_angles) / 10000
|
|
|
|
|
|
- print(f'angle_loss:{angle_loss.item()}, param_loss:{param_loss.item()}')
|
|
|
+ # print(f'angle_loss:{angle_loss.item()}, param_loss:{param_loss.item()}')
|
|
|
|
|
|
|
|
|
count = sum(len(sublist) for sublist in proposals)
|
|
|
- total_loss = ((param_loss + angle_loss) / count) if count > 0 else torch.tensor(0.0, device=device,
|
|
|
+ total_loss = ((param_loss + ends_loss) / count) if count > 0 else torch.tensor(0.0, device=device,
|
|
|
dtype=torch.float)
|
|
|
|
|
|
total_loss = total_loss.to(device)
|
|
|
- angle_loss = angle_loss.to(device)
|
|
|
+ ends_loss = ends_loss.to(device)
|
|
|
param_loss = param_loss.to(device)
|
|
|
|
|
|
- print(f'total_loss, param_loss, angle_loss: {total_loss.item()}, {param_loss.item()}, {angle_loss.item()}')
|
|
|
+ # print(f'total_loss, param_loss, angle_loss: {total_loss.item()}, {param_loss.item()}, {angle_loss.item()}')
|
|
|
|
|
|
- return total_loss, param_loss, angle_loss
|
|
|
+ return total_loss, param_loss, ends_loss
|
|
|
|
|
|
|
|
|
# angle_loss = F.mse_loss(pred_angles, gt_sel_angles)
|