Yichao Zhou 6 年 前
コミット
0ecee79d5c
6 ファイル変更61 行追加40 行削除
  1. 2 2
      eval-APH.py
  2. 41 15
      eval-mAPJ.py
  3. 1 1
      lcnn/models/line_vectorizer.py
  4. 1 1
      matlab/eval_release.m
  5. 2 2
      misc/lsd.py
  6. 14 19
      misc/plot-sAP.py

+ 2 - 2
eval-APH.py

@@ -32,8 +32,8 @@ plt.rcParams["font.family"] = "Times New Roman"
 del mpl.font_manager.weight_dict["roman"]
 mpl.font_manager._rebuild()
 
-image_path = "data/wireframe/valid-images/"
-line_gt_path = "data/wireframe/valid/"
+image_path = "data/york/valid/"
+line_gt_path = "data/york/valid/"
 output_size = 128
 
 

+ 41 - 15
eval-mAPJ.py

@@ -31,8 +31,9 @@ from lcnn.metric import mAPJ, post_jheatmap
 
 GT = "data/york/valid/*.npz"
 IM = "data/wireframe/valid-images/*.jpg"
-WF = "/data/wirebase/result/junc/2/17"
-AFM = "/data/wirebase/result/wireframe/afm/*.npz"
+WF = "/data/lcnn/wirebase/result/junc/2/17"
+WF = "/data/lcnn/wirebase/result/wireframe/wireframe_2_rerun-baseline_0.5_0.5_york"
+AFM = "/data/lcnn/wirebase/result/wireframe/afm/*.npz"
 AFM = "/data/lcnn/logs/york-afm/*.npz"
 
 DIST = [0.5, 1.0, 2.0]
@@ -77,7 +78,7 @@ def evaluate_lcnn(im_list, gt_list, lcnn_list):
     print(f"  {ap_jc:.1f} | {ap_joc:.1f}")
 
 
-def evaluate_wireframe(im_list, gt_list, juncs_wf):
+def evaluate_wireframe(im_list, gt_list):
     print("Compute WF mAP")
     juncs_wf = load_wf()
     all_junc = np.zeros((0, 3))
@@ -132,17 +133,41 @@ def evaluate_afm(im_list, gt_list):
 
 
 def load_wf():
-    pts = [defaultdict(int) for _ in range(500)]
-    for thres in range(10):
+    pts = [defaultdict(int) for _ in range(102)]
+    for thres in sorted(
+        [
+            0.001,
+            0.01,
+            0.1,
+            0.5,
+            10,
+            100,
+            102400,
+            150,
+            12800,
+            1600,
+            2,
+            20,
+            200,
+            204800,
+            25600,
+            30,
+            3200,
+            400,
+            50,
+            51200,
+            6,
+            6400,
+            80,
+            800,
+        ]
+    ):
         mats = sorted(glob.glob(f"{WF}/{thres}/*.mat"))
         for i, mat in enumerate(mats):
-            img = cv2.imread(mat.replace(".mat", "_5.png"))
-            juncs = loadmat(mat)["junctions"]
+            juncs = loadmat(mat)["lines"].reshape(-1, 2)
             if len(juncs) == 0:
                 continue
-            juncs[:, 0] *= 128 / img.shape[1]
-            juncs[:, 1] *= 128 / img.shape[0]
-            # juncs += 0.5
+            juncs *= 128 / 512
             for j in juncs:
                 pts[i][tuple(j)] += 1
     pts = pts[: len(mats)]
@@ -153,12 +178,13 @@ def main():
     args = docopt(__doc__)
     gt_list = sorted(glob.glob(GT))
     im_list = sorted(glob.glob(IM))
-    evaluate_afm(im_list, gt_list)
+    # evaluate_afm(im_list, gt_list)
+    evaluate_wireframe(im_list, gt_list)
 
-    for path in args["<path>"]:
-        print("Evaluating", path)
-        lcnn_list = sorted(glob.glob(osp.join(path, "*.npz")))
-        evaluate_lcnn(im_list, gt_list, lcnn_list)
+    # for path in args["<path>"]:
+    #     print("Evaluating", path)
+    #     lcnn_list = sorted(glob.glob(osp.join(path, "*.npz")))
+    #     evaluate_lcnn(im_list, gt_list, lcnn_list)
 
 
 if __name__ == "__main__":

+ 1 - 1
lcnn/models/line_vectorizer.py

@@ -159,7 +159,7 @@ class LineVectorizer(nn.Module):
             max_K = M.n_dyn_junc // n_type
             N = len(junc)
             if do_evaluation:
-                K = min(int((jmap > M.eval_junc_thres).float().sum().item()), 2 * max_K)
+                K = min(int((jmap > M.eval_junc_thres).float().sum().item()), max_K)
             else:
                 K = min(int(N * 2 + 2), max_K)
             device = jmap.device

+ 1 - 1
matlab/eval_release.m

@@ -18,7 +18,7 @@ for index=1:numResults
   filename = filename(1:end-4);
   fprintf('processed %d/%d\n', index - 2, numResults - 2)
   gtname = [line_gt_path, '/', filename, '_line.mat'];
-  imgname = [image_path, filename, '.jpg'];
+  imgname = [image_path, filename, '.png'];
   
   I = imread(imgname);
   height = size(I,1);

+ 2 - 2
misc/lsd.py

@@ -12,7 +12,7 @@ import matplotlib as mpl
 import numpy.linalg as LA
 import matplotlib.pyplot as plt
 
-IM = "data/wireframe/valid-images/*.jpg"
+IM = "data/york/valid/*.png"
 
 
 if __name__ == "__main__":
@@ -30,7 +30,7 @@ if __name__ == "__main__":
 
         lsd_index = np.argsort(-lsd_score)
         np.savez_compressed(
-            iname.replace(".jpg", "_LSD.npz"),
+            iname.replace(".png", "_LSD.npz"),
             lines=lsd_line[lsd_index],
             scores=lsd_score[lsd_index],
         )

+ 14 - 19
misc/plot-sAP.py

@@ -20,13 +20,10 @@ except Exception:
     raise
 
 # Change the directory here
-PRED = "logs/190418-201834-f8934c6-lr4d10/npz/000312000/*.npz"
-PRED = "post/jmap_0008/*.npz"
-GT = "data/wireframe/valid/*.npz"
-# PRED = "logs/190506-001532-york/*.npz"
-# GT = "data/york/valid/*.npz"
-WF = "/data/lcnn/wirebase/result/wireframe/wireframe_1_rerun-baseline_0.5_0.5/*"
-AFM = "/data/lcnn/wirebase/result/wireframe/afm/*.npz"
+PRED = "/data/lcnn/logs/190815-213543-york/*.npz"
+GT = "data/york/valid/*.npz"
+WF = "/data/lcnn/wirebase/result/wireframe/wireframe_2_rerun-baseline_0.5_0.5_york/*"
+AFM = "/data/lcnn/logs/york-afm/*.npz"
 
 
 mpl.rcParams.update({"font.size": 16})
@@ -49,13 +46,13 @@ def wireframe_score(T=10):
         tp, fp, total_gt = 0, 0, 0
         for i, (gt_name, matf) in enumerate(zip(gts, mat_files)):
             line_pred = scipy.io.loadmat(matf)["lines"].reshape(-1, 2, 2)
-            img = cv2.imread(matf.replace(".mat", ".jpg"))
-            line_pred[:, :, 0] *= 128 / img.shape[1]
-            line_pred[:, :, 1] *= 128 / img.shape[0]
+            line_pred[:, :, 0] *= 128 / 512
+            line_pred[:, :, 1] *= 128 / 512
             line_pred = line_pred[:, :, ::-1]
 
             with np.load(gt_name) as fgt:
                 line_gt = fgt["lpos"][:, :, :2]
+
             tp_, fp_ = lcnn.metric.msTPFP(line_pred, line_gt, T)
             tp += tp_.sum()
             fp += fp_.sum()
@@ -71,7 +68,7 @@ def wireframe_score(T=10):
     ap = np.sum((recall[i + 1] - recall[i]) * precision[i + 1])
 
     np.savez(
-        "/data/lcnn/results/sAP/wireframe.npz",
+        "/data/lcnn/results/York/sAP/wireframe.npz",
         x=np.maximum(0.005, recall[:-1]),
         y=precision[:-1],
     )
@@ -113,12 +110,8 @@ def line_score(threshold=10):
             gt_line = fgt["lpos"][:, :, :2]
 
         with np.load(afm_name) as fafm:
-            afm_line = fafm["lines"].reshape(-1, 2, 2)[:, :, ::-1]
-            afm_score = -fafm["scores"]
-            h = fafm["h"]
-            w = fafm["w"]
-        afm_line[:, :, 0] *= 128 / h
-        afm_line[:, :, 1] *= 128 / w
+            afm_line = fafm["lines"].reshape(-1, 2, 2)
+            afm_score = fafm["score"]
         for i, ((a, b), s) in enumerate(zip(lcnn_line, lcnn_score)):
             if i > 0 and (lcnn_line[i] == lcnn_line[0]).all():
                 lcnn_line = lcnn_line[:i]
@@ -193,10 +186,12 @@ def line_score(threshold=10):
         lcnn_re[lcnn_re > T], lcnn_pr[lcnn_re > T], label="L-CNN", linewidth=3, c="C3"
     )
     np.savez(
-        "/data/lcnn/results/sAP/afm.npz", x=afm_re[afm_re > T], y=afm_pr[afm_re > T]
+        "/data/lcnn/results/York/sAP/afm.npz", x=afm_re[afm_re > T], y=afm_pr[afm_re > T]
     )
     np.savez(
-        "/data/lcnn/results/sAP/lcnn.npz", x=lcnn_re[lcnn_re > T], y=lcnn_pr[lcnn_re > T]
+        "/data/lcnn/results/York/sAP/lcnn.npz",
+        x=lcnn_re[lcnn_re > T],
+        y=lcnn_pr[lcnn_re > T],
     )
     # plt.plot(lsd_re, lsd_pr, label="LSD", linewidth=2)