|
@@ -1069,6 +1069,7 @@ class RoIHeads(nn.Module):
|
|
|
losses.update(loss_line)
|
|
losses.update(loss_line)
|
|
|
losses.update(loss_line_iou)
|
|
losses.update(loss_line_iou)
|
|
|
print(f'losses:{losses}')
|
|
print(f'losses:{losses}')
|
|
|
|
|
+
|
|
|
if self.has_point() and self.detect_point:
|
|
if self.has_point() and self.detect_point:
|
|
|
print(f'roi_heads forward has_point()!!!!')
|
|
print(f'roi_heads forward has_point()!!!!')
|
|
|
# print(f'labels:{labels}')
|
|
# print(f'labels:{labels}')
|
|
@@ -1188,7 +1189,6 @@ class RoIHeads(nn.Module):
|
|
|
losses.update(loss_point)
|
|
losses.update(loss_point)
|
|
|
print(f'losses:{losses}')
|
|
print(f'losses:{losses}')
|
|
|
|
|
|
|
|
-
|
|
|
|
|
if self.has_arc() and self.detect_arc:
|
|
if self.has_arc() and self.detect_arc:
|
|
|
print(f'roi_heads forward has_arc()!!!!')
|
|
print(f'roi_heads forward has_arc()!!!!')
|
|
|
# print(f'labels:{labels}')
|
|
# print(f'labels:{labels}')
|
|
@@ -1320,7 +1320,6 @@ class RoIHeads(nn.Module):
|
|
|
# print(f'ins_proposals11:{ins_proposals}')
|
|
# print(f'ins_proposals11:{ins_proposals}')
|
|
|
print(f'boxes_proposals:{len(ins_proposals)}')
|
|
print(f'boxes_proposals:{len(ins_proposals)}')
|
|
|
|
|
|
|
|
-
|
|
|
|
|
if self.training:
|
|
if self.training:
|
|
|
# during training, only focus on positive boxes
|
|
# during training, only focus on positive boxes
|
|
|
num_images = len(proposals)
|
|
num_images = len(proposals)
|
|
@@ -1331,9 +1330,6 @@ class RoIHeads(nn.Module):
|
|
|
raise ValueError("if in trainning, matched_idxs should not be None")
|
|
raise ValueError("if in trainning, matched_idxs should not be None")
|
|
|
for img_id in range(num_images):
|
|
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]
|
|
circle_pos = torch.where(labels[img_id] == 4)[0]
|
|
|
circle_pos = circle_pos.flatten()
|
|
circle_pos = circle_pos.flatten()
|
|
|
idxs = circle_pos.detach().cpu().tolist()
|
|
idxs = circle_pos.detach().cpu().tolist()
|
|
@@ -1344,12 +1340,8 @@ class RoIHeads(nn.Module):
|
|
|
f"Index out of bounds: circle_pos={idx}, but proposals len={num_prop}, "
|
|
f"Index out of bounds: circle_pos={idx}, but proposals len={num_prop}, "
|
|
|
f"img_id={img_id}"
|
|
f"img_id={img_id}"
|
|
|
)
|
|
)
|
|
|
- ins_proposals.append(
|
|
|
|
|
- proposals[img_id][idxs]
|
|
|
|
|
- )
|
|
|
|
|
- ins_pos_matched_idxs.append(
|
|
|
|
|
- matched_idxs[img_id][idxs]
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ ins_proposals.append(proposals[img_id][idxs])
|
|
|
|
|
+ ins_pos_matched_idxs.append(matched_idxs[img_id][idxs])
|
|
|
print(f'ins_proposals in train:{ins_proposals}')
|
|
print(f'ins_proposals in train:{ins_proposals}')
|
|
|
else:
|
|
else:
|
|
|
if targets is not None:
|
|
if targets is not None:
|
|
@@ -1363,9 +1355,6 @@ class RoIHeads(nn.Module):
|
|
|
raise ValueError("if in trainning, matched_idxs should not be None")
|
|
raise ValueError("if in trainning, matched_idxs should not be None")
|
|
|
|
|
|
|
|
for img_id in range(num_images):
|
|
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]
|
|
circle_pos = torch.where(labels[img_id] == 4)[0]
|
|
|
circle_pos = circle_pos.flatten()
|
|
circle_pos = circle_pos.flatten()
|
|
|
idxs = circle_pos.detach().cpu().tolist()
|
|
idxs = circle_pos.detach().cpu().tolist()
|
|
@@ -1376,12 +1365,8 @@ class RoIHeads(nn.Module):
|
|
|
f"Index out of bounds: circle_pos={idx}, but proposals len={num_prop}, "
|
|
f"Index out of bounds: circle_pos={idx}, but proposals len={num_prop}, "
|
|
|
f"img_id={img_id}"
|
|
f"img_id={img_id}"
|
|
|
)
|
|
)
|
|
|
- ins_proposals.append(
|
|
|
|
|
- proposals[img_id][idxs]
|
|
|
|
|
- )
|
|
|
|
|
- ins_pos_matched_idxs.append(
|
|
|
|
|
- matched_idxs[img_id][idxs]
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ ins_proposals.append(proposals[img_id][idxs])
|
|
|
|
|
+ ins_pos_matched_idxs.append(matched_idxs[img_id][idxs])
|
|
|
print(f'ins_proposals in val:{ins_proposals}')
|
|
print(f'ins_proposals in val:{ins_proposals}')
|
|
|
else:
|
|
else:
|
|
|
pos_matched_idxs = None
|
|
pos_matched_idxs = None
|
|
@@ -1389,17 +1374,21 @@ class RoIHeads(nn.Module):
|
|
|
# circle_proposals_tensor=torch.cat(circle_proposals)
|
|
# circle_proposals_tensor=torch.cat(circle_proposals)
|
|
|
|
|
|
|
|
ins_proposals_valid = self.check_proposals(ins_proposals)
|
|
ins_proposals_valid = self.check_proposals(ins_proposals)
|
|
|
- print(f"self.train{self.training}")
|
|
|
|
|
- print(f"self.val{ins_proposals_valid}")
|
|
|
|
|
- if ins_proposals_valid:
|
|
|
|
|
|
|
+ print(f"self.train:{self.training}")
|
|
|
|
|
+ print(f"proposals_valid:{ins_proposals_valid}")
|
|
|
|
|
|
|
|
|
|
+ if ins_proposals_valid:
|
|
|
print(f'features from backbone:{features['0'].shape}')
|
|
print(f'features from backbone:{features['0'].shape}')
|
|
|
print(f'ins_proposals in ins_forward1:{ins_proposals}')
|
|
print(f'ins_proposals in ins_forward1:{ins_proposals}')
|
|
|
feature_logits = self.ins_forward1(features, image_shapes, ins_proposals)
|
|
feature_logits = self.ins_forward1(features, image_shapes, ins_proposals)
|
|
|
# ins_masks, ins_scores, circle_points = ins_inference(feature_logits,
|
|
# ins_masks, ins_scores, circle_points = ins_inference(feature_logits,
|
|
|
# ins_proposals, th=0)
|
|
# ins_proposals, th=0)
|
|
|
|
|
|
|
|
- arc_equation = self.arc_equation_head(feature_logits) # [proposal和,7]
|
|
|
|
|
|
|
+ # plt.title('feature_logits')
|
|
|
|
|
+ # plt.imshow(feature_logits[0][0].cpu().detach().numpy())
|
|
|
|
|
+ # plt.show()
|
|
|
|
|
+
|
|
|
|
|
+ arc_equation = self.arc_equation_head(feature_logits) # [proposal和,9]
|
|
|
|
|
|
|
|
loss_ins = None
|
|
loss_ins = None
|
|
|
loss_ins_extra=None
|
|
loss_ins_extra=None
|
|
@@ -1419,9 +1408,8 @@ class RoIHeads(nn.Module):
|
|
|
gt_mask_ends = [t["mask_ends"] for t in targets if "mask_ends" in t]
|
|
gt_mask_ends = [t["mask_ends"] for t in targets if "mask_ends" in t]
|
|
|
gt_mask_params = [t["mask_params"] for t in targets if "mask_params" in t]
|
|
gt_mask_params = [t["mask_params"] for t in targets if "mask_params" in t]
|
|
|
|
|
|
|
|
- # print(f'gt_ins:{gt_inses[0].shape}')
|
|
|
|
|
- h, w = targets[0]["img_size"]
|
|
|
|
|
- img_size = h
|
|
|
|
|
|
|
+ # h, w = targets[0]["img_size"]
|
|
|
|
|
+ # img_size = h
|
|
|
|
|
|
|
|
gt_ins_tensor = torch.zeros(0, 0)
|
|
gt_ins_tensor = torch.zeros(0, 0)
|
|
|
if len(gt_inses) > 0:
|
|
if len(gt_inses) > 0:
|
|
@@ -1431,7 +1419,6 @@ class RoIHeads(nn.Module):
|
|
|
|
|
|
|
|
if gt_ins_tensor.shape[0] > 0:
|
|
if gt_ins_tensor.shape[0] > 0:
|
|
|
print(f'start to compute circle_loss')
|
|
print(f'start to compute circle_loss')
|
|
|
-
|
|
|
|
|
loss_ins = compute_ins_loss(feature_logits, ins_proposals, gt_inses,ins_pos_matched_idxs)
|
|
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_ends,gt_mask_params,ins_pos_matched_idxs,labels)
|
|
|
# loss_arc_ends = loss_arc_ends
|
|
# loss_arc_ends = loss_arc_ends
|
|
@@ -1447,20 +1434,19 @@ class RoIHeads(nn.Module):
|
|
|
print(f'loss_ins is None111')
|
|
print(f'loss_ins is None111')
|
|
|
loss_ins = torch.tensor(0.0, device=device)
|
|
loss_ins = torch.tensor(0.0, device=device)
|
|
|
|
|
|
|
|
- if loss_ins_extra is None:
|
|
|
|
|
- print(f'loss_ins_extra is None111')
|
|
|
|
|
- loss_ins_extra = torch.tensor(0.0, device=device)
|
|
|
|
|
|
|
+ # if loss_ins_extra is None:
|
|
|
|
|
+ # print(f'loss_ins_extra is None111')
|
|
|
|
|
+ # loss_ins_extra = torch.tensor(0.0, device=device)
|
|
|
|
|
|
|
|
loss_ins = {"loss_ins": loss_ins}
|
|
loss_ins = {"loss_ins": loss_ins}
|
|
|
# loss_ins_extra = {"loss_ins_extra": loss_ins_extra}
|
|
# loss_ins_extra = {"loss_ins_extra": loss_ins_extra}
|
|
|
# loss_arc_equation = {"loss_arc_equation": loss_arc_equation}
|
|
# loss_arc_equation = {"loss_arc_equation": loss_arc_equation}
|
|
|
# loss_arc_ends = {"loss_arc_ends": loss_arc_ends}
|
|
# loss_arc_ends = {"loss_arc_ends": loss_arc_ends}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
else:
|
|
else:
|
|
|
if targets is not None:
|
|
if targets is not None:
|
|
|
- h, w = targets[0]["img_size"]
|
|
|
|
|
- img_size = h
|
|
|
|
|
|
|
+ # h, w = targets[0]["img_size"]
|
|
|
|
|
+ # img_size = h
|
|
|
gt_inses = [t["circle_masks"] for t in targets if "circle_masks" in t]
|
|
gt_inses = [t["circle_masks"] for t in targets if "circle_masks" in t]
|
|
|
gt_labels = [t["labels"] for t in targets]
|
|
gt_labels = [t["labels"] for t in targets]
|
|
|
gt_mask_ends = [t["mask_ends"] for t in targets if "mask_ends" in t]
|
|
gt_mask_ends = [t["mask_ends"] for t in targets if "mask_ends" in t]
|
|
@@ -1473,17 +1459,16 @@ class RoIHeads(nn.Module):
|
|
|
if gt_ins_tensor.shape[0] > 0:
|
|
if gt_ins_tensor.shape[0] > 0:
|
|
|
print(f'start to compute circle_loss')
|
|
print(f'start to compute circle_loss')
|
|
|
|
|
|
|
|
- loss_ins = compute_ins_loss(feature_logits, ins_proposals, gt_inses,
|
|
|
|
|
- ins_pos_matched_idxs)
|
|
|
|
|
|
|
+ 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_ends,gt_mask_params,ins_pos_matched_idxs,labels)
|
|
|
#
|
|
#
|
|
|
# loss_arc_ends = loss_arc_ends
|
|
# loss_arc_ends = loss_arc_ends
|
|
|
|
|
|
|
|
# loss_ins_extra = compute_circle_extra_losses(feature_logits, circle_proposals, gt_circles,circle_pos_matched_idxs)
|
|
# loss_ins_extra = compute_circle_extra_losses(feature_logits, circle_proposals, gt_circles,circle_pos_matched_idxs)
|
|
|
|
|
|
|
|
- # if loss_ins is None:
|
|
|
|
|
- # print(f'loss_ins is None111')
|
|
|
|
|
- # loss_ins = torch.tensor(0.0, device=device)
|
|
|
|
|
|
|
+ if loss_ins is None:
|
|
|
|
|
+ print(f'loss_ins is None111')
|
|
|
|
|
+ loss_ins = torch.tensor(0.0, device=device)
|
|
|
|
|
|
|
|
# if loss_ins_extra is None:
|
|
# if loss_ins_extra is None:
|
|
|
# print(f'loss_ins_extra is None111')
|
|
# print(f'loss_ins_extra is None111')
|
|
@@ -1497,21 +1482,11 @@ class RoIHeads(nn.Module):
|
|
|
# print(f'loss_arc_ends is None')
|
|
# print(f'loss_arc_ends is None')
|
|
|
# loss_arc_ends = torch.tensor(0.0, device=device)
|
|
# loss_arc_ends = torch.tensor(0.0, device=device)
|
|
|
|
|
|
|
|
- if loss_ins is None:
|
|
|
|
|
- print(f'loss_ins is None111')
|
|
|
|
|
- loss_ins = torch.tensor(0.0, device=device)
|
|
|
|
|
-
|
|
|
|
|
- # if loss_ins_extra is None:
|
|
|
|
|
- # print(f'loss_ins_extra is None111')
|
|
|
|
|
- # loss_ins_extra = torch.tensor(0.0, device=device)
|
|
|
|
|
-
|
|
|
|
|
loss_ins = {"loss_ins": loss_ins}
|
|
loss_ins = {"loss_ins": loss_ins}
|
|
|
# loss_ins_extra = {"loss_ins_extra": loss_ins_extra}
|
|
# loss_ins_extra = {"loss_ins_extra": loss_ins_extra}
|
|
|
# loss_arc_equation = {"loss_arc_equation": loss_arc_equation}
|
|
# loss_arc_equation = {"loss_arc_equation": loss_arc_equation}
|
|
|
# loss_arc_ends = {"loss_arc_ends": loss_arc_ends}
|
|
# loss_arc_ends = {"loss_arc_ends": loss_arc_ends}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
else:
|
|
else:
|
|
|
loss_ins = {}
|
|
loss_ins = {}
|
|
|
# loss_ins_extra = {}
|
|
# loss_ins_extra = {}
|
|
@@ -1551,7 +1526,7 @@ class RoIHeads(nn.Module):
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f'loss_ins:{loss_ins}')
|
|
print(f'loss_ins:{loss_ins}')
|
|
|
- print(f'loss_ins_extra:{loss_ins_extra}')
|
|
|
|
|
|
|
+ # print(f'loss_ins_extra:{loss_ins_extra}')
|
|
|
losses.update(loss_ins)
|
|
losses.update(loss_ins)
|
|
|
# losses.update(loss_ins_extra)
|
|
# losses.update(loss_ins_extra)
|
|
|
# losses.update(loss_arc_equation)
|
|
# losses.update(loss_arc_equation)
|