Forráskód Böngészése

arc ends and params is OK in loss and draw in trainer

Your Name 2 hete
szülő
commit
40ab2b1281

+ 8 - 9
libs/vision_libs/models/detection/transform.py

@@ -236,6 +236,7 @@ class GeneralizedRCNNTransform(nn.Module):
         if "mask_params" in target:
             arc_mask = target["mask_params"]
             arc_mask = resize_keypoints(arc_mask, (h, w), image.shape[-2:])
+            arc_mask[:,2:4] = resize_keypoints(arc_mask[:,2:4], (h, w), image.shape[-2:])
             target["mask_params"] = arc_mask
         return image, target
 
@@ -330,15 +331,13 @@ class GeneralizedRCNNTransform(nn.Module):
                 masks = paste_masks_in_image(masks, boxes, o_im_s)
                 result[i]["circle_masks"] = masks
 
-            if "mask_ends" in pred:
-                arc_mask = pred["mask_ends"]
-                arc_mask = resize_keypoints(arc_mask,im_s, o_im_s)
-                result[i]["mask_ends"] = arc_mask
-            if "mask_params" in pred:
-                arc_mask = pred["mask_params"]
-                arc_mask = resize_keypoints(arc_mask, im_s, o_im_s)
-                result[i]["mask_params"] = arc_mask
-
+            if "arcs" in pred:
+                arc_mask = pred["arcs"]
+                arc_mask[:,0:2] = resize_keypoints(arc_mask[:,0:2],im_s, o_im_s)
+                arc_mask[:,2:4] = resize_keypoints(arc_mask[:,2:4], im_s, o_im_s)
+                arc_mask[:,5:7] = resize_keypoints(arc_mask[:,5:7], im_s, o_im_s)
+                arc_mask[:,7:9] = resize_keypoints(arc_mask[:,7:9], im_s, o_im_s)
+                result[i]["arcs"] = arc_mask
 
         return result
 

+ 1 - 1
models/line_detect/heads/arc/arc_heads.py

@@ -121,7 +121,7 @@ class ArcEquationHead(nn.Module):
         # Last two values are auxiliary points
         # Now mapped to the same spatial range as image
         # ------------------------------------------------
-        arc_params[..., 5] = torch.sigmoid(arc_params[..., 5]) * W   # x auxiliary
+        arc_params[..., 5] = 7   # x auxiliary
         arc_params[..., 6] = torch.sigmoid(arc_params[..., 6]) * H   # y auxiliary
         arc_params[..., 7] = torch.sigmoid(arc_params[..., 7]) * W  # x auxiliary
         arc_params[..., 8] = torch.sigmoid(arc_params[..., 8]) * H  # y auxiliary

+ 9 - 10
models/line_detect/loi_heads.py

@@ -1312,13 +1312,14 @@ class RoIHeads(nn.Module):
 
         if self.has_ins and self.detect_ins:
             print(f'roi_heads forward has_circle()!!!!')
-            # print(f'labels:{labels}')
-            ins_proposals = [p["boxes"] for p in result]
+            print(f'labels:{labels}')
+            # for p in result:
+            #     print(f'p["boxes"]:{p["boxes"]}')
+            #     print(f'p["labels"]:{p["labels"]}')
+            ins_proposals = [p["boxes"][p["labels"] == 4] for p in result]
+            # print(f'ins_proposals11:{ins_proposals}')
             print(f'boxes_proposals:{len(ins_proposals)}')
 
-            # if line_proposals is None or len(line_proposals) == 0:
-            #     # 返回空特征或者跳过该部分计算
-            #     return torch.empty(0, C, H, W).to(features['0'].device)
 
             if self.training:
                 # during training, only focus on positive boxes
@@ -1349,6 +1350,7 @@ class RoIHeads(nn.Module):
                     ins_pos_matched_idxs.append(
                         matched_idxs[img_id][idxs]
                     )
+                    print(f'ins_proposals in train:{ins_proposals}')
             else:
                 if targets is not None:
 
@@ -1380,7 +1382,7 @@ class RoIHeads(nn.Module):
                         ins_pos_matched_idxs.append(
                             matched_idxs[img_id][idxs]
                         )
-
+                        print(f'ins_proposals in val:{ins_proposals}')
                 else:
                     pos_matched_idxs = None
 
@@ -1391,15 +1393,12 @@ class RoIHeads(nn.Module):
             print(f"self.val{ins_proposals_valid}")
             if  ins_proposals_valid:
 
-
-
                 print(f'features from backbone:{features['0'].shape}')
+                print(f'ins_proposals in ins_forward1:{ins_proposals}')
                 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]
 
                 loss_ins = None

+ 9 - 9
models/line_detect/trainer.py

@@ -175,14 +175,14 @@ def draw_el(all, background_img):
     # Unpack parameters
     cx, cy, a, b, theta_deg, x1, y1, x2, y2 = all
 
-    cx = cx / 672 * 2000
-    cy = cy / 672 * 2000
-    # a = a / 672 * 2000
-    # b = b / 672 * 2000
-    x1 = x1 / 672 * 2000
-    y1 = y1 / 672 * 2000
-    x2 = x2 / 672 * 2000
-    y2 = y2 / 672 * 2000
+    # cx = cx / 672 * 2000
+    # cy = cy / 672 * 2000
+    # # a = a / 672 * 2000
+    # # b = b / 672 * 2000
+    # x1 = x1 / 672 * 2000
+    # y1 = y1 / 672 * 2000
+    # x2 = x2 / 672 * 2000
+    # y2 = y2 / 672 * 2000
 
 
 
@@ -435,7 +435,7 @@ class Trainer(BaseTrainer):
 
         if 'arcs' in result:
             arcs = result['arcs'][0]
-            print(f'arcs in dra w:{arcs}')
+            print(f'arcs in draw:{arcs}')
 
             ellipse_img = draw_el(arcs, background_img=im)