Spaces:
Running
on
Zero
Running
on
Zero
update: imcui
Browse files- imcui/ui/app_class.py +22 -12
- imcui/ui/utils.py +67 -8
imcui/ui/app_class.py
CHANGED
|
@@ -47,6 +47,7 @@ class ImageMatchingApp:
|
|
| 47 |
self.example_data_root = kwargs.get(
|
| 48 |
"example_data_root", Path(__file__).parents[1] / "datasets"
|
| 49 |
)
|
|
|
|
| 50 |
self.init_interface()
|
| 51 |
|
| 52 |
def init_matcher_dropdown(self):
|
|
@@ -107,6 +108,8 @@ class ImageMatchingApp:
|
|
| 107 |
with gr.Row():
|
| 108 |
button_reset = gr.Button(value="Reset")
|
| 109 |
button_run = gr.Button(value="Run Match", variant="primary")
|
|
|
|
|
|
|
| 110 |
|
| 111 |
with gr.Accordion("Advanced Setting", open=False):
|
| 112 |
with gr.Accordion("Image Setting", open=True):
|
|
@@ -326,7 +329,14 @@ class ImageMatchingApp:
|
|
| 326 |
output_pred,
|
| 327 |
]
|
| 328 |
# button callbacks
|
| 329 |
-
button_run.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
# Reset images
|
| 331 |
reset_outputs = [
|
| 332 |
input_image0,
|
|
@@ -519,11 +529,11 @@ class ImageMatchingApp:
|
|
| 519 |
markdown_table = "| Algo. | Conference | Code | Project | Paper |\n"
|
| 520 |
markdown_table += "| ----- | ---------- | ---- | ------- | ----- |\n"
|
| 521 |
|
| 522 |
-
for
|
| 523 |
-
if not v["info"]
|
| 524 |
continue
|
| 525 |
-
github_link = get_link(v["info"]
|
| 526 |
-
project_link = get_link(v["info"]
|
| 527 |
paper_link = get_link(
|
| 528 |
v["info"]["paper"],
|
| 529 |
(
|
|
@@ -534,8 +544,8 @@ class ImageMatchingApp:
|
|
| 534 |
)
|
| 535 |
|
| 536 |
markdown_table += "{}|{}|{}|{}|{}\n".format(
|
| 537 |
-
v["info"]
|
| 538 |
-
v["info"]
|
| 539 |
github_link,
|
| 540 |
project_link,
|
| 541 |
paper_link,
|
|
@@ -547,11 +557,11 @@ class ImageMatchingApp:
|
|
| 547 |
continue
|
| 548 |
data.append(
|
| 549 |
[
|
| 550 |
-
v["info"]
|
| 551 |
-
v["info"]
|
| 552 |
-
v["info"]
|
| 553 |
-
v["info"]
|
| 554 |
-
v["info"]
|
| 555 |
]
|
| 556 |
)
|
| 557 |
tab = gr.Dataframe(
|
|
|
|
| 47 |
self.example_data_root = kwargs.get(
|
| 48 |
"example_data_root", Path(__file__).parents[1] / "datasets"
|
| 49 |
)
|
| 50 |
+
# final step
|
| 51 |
self.init_interface()
|
| 52 |
|
| 53 |
def init_matcher_dropdown(self):
|
|
|
|
| 108 |
with gr.Row():
|
| 109 |
button_reset = gr.Button(value="Reset")
|
| 110 |
button_run = gr.Button(value="Run Match", variant="primary")
|
| 111 |
+
with gr.Row():
|
| 112 |
+
button_stop = gr.Button(value="Force Stop", variant="stop")
|
| 113 |
|
| 114 |
with gr.Accordion("Advanced Setting", open=False):
|
| 115 |
with gr.Accordion("Image Setting", open=True):
|
|
|
|
| 329 |
output_pred,
|
| 330 |
]
|
| 331 |
# button callbacks
|
| 332 |
+
click_event = button_run.click(
|
| 333 |
+
fn=run_matching, inputs=inputs, outputs=outputs
|
| 334 |
+
)
|
| 335 |
+
# stop button
|
| 336 |
+
button_stop.click(
|
| 337 |
+
fn=None, inputs=None, outputs=None, cancels=[click_event]
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
# Reset images
|
| 341 |
reset_outputs = [
|
| 342 |
input_image0,
|
|
|
|
| 529 |
markdown_table = "| Algo. | Conference | Code | Project | Paper |\n"
|
| 530 |
markdown_table += "| ----- | ---------- | ---- | ------- | ----- |\n"
|
| 531 |
|
| 532 |
+
for _, v in cfg.items():
|
| 533 |
+
if not v["info"].get("display", True):
|
| 534 |
continue
|
| 535 |
+
github_link = get_link(v["info"].get("github", ""))
|
| 536 |
+
project_link = get_link(v["info"].get("project", ""))
|
| 537 |
paper_link = get_link(
|
| 538 |
v["info"]["paper"],
|
| 539 |
(
|
|
|
|
| 544 |
)
|
| 545 |
|
| 546 |
markdown_table += "{}|{}|{}|{}|{}\n".format(
|
| 547 |
+
v["info"].get("name", ""),
|
| 548 |
+
v["info"].get("source", ""),
|
| 549 |
github_link,
|
| 550 |
project_link,
|
| 551 |
paper_link,
|
|
|
|
| 557 |
continue
|
| 558 |
data.append(
|
| 559 |
[
|
| 560 |
+
v["info"].get("name", ""),
|
| 561 |
+
v["info"].get("source", ""),
|
| 562 |
+
v["info"].get("github", ""),
|
| 563 |
+
v["info"].get("paper", ""),
|
| 564 |
+
v["info"].get("project", ""),
|
| 565 |
]
|
| 566 |
)
|
| 567 |
tab = gr.Dataframe(
|
imcui/ui/utils.py
CHANGED
|
@@ -153,12 +153,14 @@ def parse_match_config(conf):
|
|
| 153 |
return {
|
| 154 |
"matcher": match_dense.confs.get(conf["matcher"]),
|
| 155 |
"dense": True,
|
|
|
|
| 156 |
}
|
| 157 |
else:
|
| 158 |
return {
|
| 159 |
"feature": extract_features.confs.get(conf["feature"]),
|
| 160 |
"matcher": match_features.confs.get(conf["matcher"]),
|
| 161 |
"dense": False,
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
|
|
@@ -842,6 +844,32 @@ def run_ransac(
|
|
| 842 |
)
|
| 843 |
|
| 844 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
def run_matching(
|
| 846 |
image0: np.ndarray,
|
| 847 |
image1: np.ndarray,
|
|
@@ -911,12 +939,6 @@ def run_matching(
|
|
| 911 |
output_matches_raw = None
|
| 912 |
output_matches_ransac = None
|
| 913 |
|
| 914 |
-
# super slow!
|
| 915 |
-
if "roma" in key.lower() and DEVICE == "cpu":
|
| 916 |
-
gr.Info(
|
| 917 |
-
f"Success! Please be patient and allow for about 2-3 minutes."
|
| 918 |
-
f" Due to CPU inference, {key} is quiet slow."
|
| 919 |
-
)
|
| 920 |
t0 = time.time()
|
| 921 |
model = matcher_zoo[key]
|
| 922 |
match_conf = model["matcher"]
|
|
@@ -924,6 +946,15 @@ def run_matching(
|
|
| 924 |
match_conf["model"]["match_threshold"] = match_threshold
|
| 925 |
match_conf["model"]["max_keypoints"] = extract_max_keypoints
|
| 926 |
cache_key = "{}_{}".format(key, match_conf["model"]["name"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
if use_cached_model:
|
| 928 |
# because of the model cache, we need to update the config
|
| 929 |
matcher = model_cache.cache_model(cache_key, get_model, match_conf)
|
|
@@ -934,6 +965,9 @@ def run_matching(
|
|
| 934 |
matcher = get_model(match_conf)
|
| 935 |
logger.info(f"Loading model using: {time.time()-t0:.3f}s")
|
| 936 |
t1 = time.time()
|
|
|
|
|
|
|
|
|
|
| 937 |
|
| 938 |
if model["dense"]:
|
| 939 |
if not match_conf["preprocessing"].get("force_resize", False):
|
|
@@ -997,6 +1031,14 @@ def run_matching(
|
|
| 997 |
"Image 1 - Keypoints",
|
| 998 |
]
|
| 999 |
output_keypoints = display_keypoints(pred, titles=titles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1000 |
|
| 1001 |
# plot images with raw matches
|
| 1002 |
titles = [
|
|
@@ -1004,6 +1046,14 @@ def run_matching(
|
|
| 1004 |
"Image 1 - Raw matched keypoints",
|
| 1005 |
]
|
| 1006 |
output_matches_raw, num_matches_raw = display_matches(pred, titles=titles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
|
| 1008 |
# if enable_ransac:
|
| 1009 |
filter_matches(
|
|
@@ -1026,9 +1076,17 @@ def run_matching(
|
|
| 1026 |
output_matches_ransac, num_matches_ransac = display_matches(
|
| 1027 |
pred, titles=titles, tag="KPTS_RANSAC"
|
| 1028 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1029 |
# gr.Info(f"Display matches done using: {time.time()-t1:.3f}s")
|
| 1030 |
logger.info(f"Display matches done using: {time.time()-t1:.3f}s")
|
| 1031 |
-
|
| 1032 |
t1 = time.time()
|
| 1033 |
# plot wrapped images
|
| 1034 |
output_wrapped, warped_image = generate_warp_images(
|
|
@@ -1051,7 +1109,8 @@ def run_matching(
|
|
| 1051 |
with open(tmp_state_cache, "wb") as f:
|
| 1052 |
pickle.dump(state_cache, f)
|
| 1053 |
logger.info("Dump results done!")
|
| 1054 |
-
|
|
|
|
| 1055 |
output_keypoints,
|
| 1056 |
output_matches_raw,
|
| 1057 |
output_matches_ransac,
|
|
|
|
| 153 |
return {
|
| 154 |
"matcher": match_dense.confs.get(conf["matcher"]),
|
| 155 |
"dense": True,
|
| 156 |
+
"info": conf.get("info", {}),
|
| 157 |
}
|
| 158 |
else:
|
| 159 |
return {
|
| 160 |
"feature": extract_features.confs.get(conf["feature"]),
|
| 161 |
"matcher": match_features.confs.get(conf["matcher"]),
|
| 162 |
"dense": False,
|
| 163 |
+
"info": conf.get("info", {}),
|
| 164 |
}
|
| 165 |
|
| 166 |
|
|
|
|
| 844 |
)
|
| 845 |
|
| 846 |
|
| 847 |
+
def generate_fake_outputs(
|
| 848 |
+
output_keypoints,
|
| 849 |
+
output_matches_raw,
|
| 850 |
+
output_matches_ransac,
|
| 851 |
+
match_conf,
|
| 852 |
+
extract_conf,
|
| 853 |
+
pred,
|
| 854 |
+
):
|
| 855 |
+
return (
|
| 856 |
+
output_keypoints,
|
| 857 |
+
output_matches_raw,
|
| 858 |
+
output_matches_ransac,
|
| 859 |
+
{},
|
| 860 |
+
{
|
| 861 |
+
"match_conf": match_conf,
|
| 862 |
+
"extractor_conf": extract_conf,
|
| 863 |
+
},
|
| 864 |
+
{
|
| 865 |
+
"geom_info": pred.get("geom_info", {}),
|
| 866 |
+
},
|
| 867 |
+
None,
|
| 868 |
+
None,
|
| 869 |
+
None,
|
| 870 |
+
)
|
| 871 |
+
|
| 872 |
+
|
| 873 |
def run_matching(
|
| 874 |
image0: np.ndarray,
|
| 875 |
image1: np.ndarray,
|
|
|
|
| 939 |
output_matches_raw = None
|
| 940 |
output_matches_ransac = None
|
| 941 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
t0 = time.time()
|
| 943 |
model = matcher_zoo[key]
|
| 944 |
match_conf = model["matcher"]
|
|
|
|
| 946 |
match_conf["model"]["match_threshold"] = match_threshold
|
| 947 |
match_conf["model"]["max_keypoints"] = extract_max_keypoints
|
| 948 |
cache_key = "{}_{}".format(key, match_conf["model"]["name"])
|
| 949 |
+
|
| 950 |
+
efficiency = model["info"].get("efficiency", "high")
|
| 951 |
+
if efficiency == "low":
|
| 952 |
+
gr.Warning(
|
| 953 |
+
"Matcher {} is time-consuming, please wait for a while".format(
|
| 954 |
+
model["info"].get("name", "unknown")
|
| 955 |
+
)
|
| 956 |
+
)
|
| 957 |
+
|
| 958 |
if use_cached_model:
|
| 959 |
# because of the model cache, we need to update the config
|
| 960 |
matcher = model_cache.cache_model(cache_key, get_model, match_conf)
|
|
|
|
| 965 |
matcher = get_model(match_conf)
|
| 966 |
logger.info(f"Loading model using: {time.time()-t0:.3f}s")
|
| 967 |
t1 = time.time()
|
| 968 |
+
yield generate_fake_outputs(
|
| 969 |
+
output_keypoints, output_matches_raw, output_matches_ransac, match_conf, {}, {}
|
| 970 |
+
)
|
| 971 |
|
| 972 |
if model["dense"]:
|
| 973 |
if not match_conf["preprocessing"].get("force_resize", False):
|
|
|
|
| 1031 |
"Image 1 - Keypoints",
|
| 1032 |
]
|
| 1033 |
output_keypoints = display_keypoints(pred, titles=titles)
|
| 1034 |
+
yield generate_fake_outputs(
|
| 1035 |
+
output_keypoints,
|
| 1036 |
+
output_matches_raw,
|
| 1037 |
+
output_matches_ransac,
|
| 1038 |
+
match_conf,
|
| 1039 |
+
extract_conf,
|
| 1040 |
+
pred,
|
| 1041 |
+
)
|
| 1042 |
|
| 1043 |
# plot images with raw matches
|
| 1044 |
titles = [
|
|
|
|
| 1046 |
"Image 1 - Raw matched keypoints",
|
| 1047 |
]
|
| 1048 |
output_matches_raw, num_matches_raw = display_matches(pred, titles=titles)
|
| 1049 |
+
yield generate_fake_outputs(
|
| 1050 |
+
output_keypoints,
|
| 1051 |
+
output_matches_raw,
|
| 1052 |
+
output_matches_ransac,
|
| 1053 |
+
match_conf,
|
| 1054 |
+
extract_conf,
|
| 1055 |
+
pred,
|
| 1056 |
+
)
|
| 1057 |
|
| 1058 |
# if enable_ransac:
|
| 1059 |
filter_matches(
|
|
|
|
| 1076 |
output_matches_ransac, num_matches_ransac = display_matches(
|
| 1077 |
pred, titles=titles, tag="KPTS_RANSAC"
|
| 1078 |
)
|
| 1079 |
+
yield generate_fake_outputs(
|
| 1080 |
+
output_keypoints,
|
| 1081 |
+
output_matches_raw,
|
| 1082 |
+
output_matches_ransac,
|
| 1083 |
+
match_conf,
|
| 1084 |
+
extract_conf,
|
| 1085 |
+
pred,
|
| 1086 |
+
)
|
| 1087 |
+
|
| 1088 |
# gr.Info(f"Display matches done using: {time.time()-t1:.3f}s")
|
| 1089 |
logger.info(f"Display matches done using: {time.time()-t1:.3f}s")
|
|
|
|
| 1090 |
t1 = time.time()
|
| 1091 |
# plot wrapped images
|
| 1092 |
output_wrapped, warped_image = generate_warp_images(
|
|
|
|
| 1109 |
with open(tmp_state_cache, "wb") as f:
|
| 1110 |
pickle.dump(state_cache, f)
|
| 1111 |
logger.info("Dump results done!")
|
| 1112 |
+
|
| 1113 |
+
yield (
|
| 1114 |
output_keypoints,
|
| 1115 |
output_matches_raw,
|
| 1116 |
output_matches_ransac,
|