Spaces:
Running
Running
Realcat
commited on
Commit
•
2f1d0e2
1
Parent(s):
a44851c
add: logger
Browse files- .gitignore +1 -0
- hloc/__init__.py +27 -4
- ui/app_class.py +31 -29
- ui/utils.py +3 -3
.gitignore
CHANGED
@@ -20,6 +20,7 @@ third_party/QuadTreeAttention
|
|
20 |
desktop.ini
|
21 |
*.egg-info
|
22 |
output.pkl
|
|
|
23 |
experiments*
|
24 |
gen_example.py
|
25 |
datasets/lines/terrace0.JPG
|
|
|
20 |
desktop.ini
|
21 |
*.egg-info
|
22 |
output.pkl
|
23 |
+
log.txt
|
24 |
experiments*
|
25 |
gen_example.py
|
26 |
datasets/lines/terrace0.JPG
|
hloc/__init__.py
CHANGED
@@ -1,21 +1,44 @@
|
|
1 |
import logging
|
|
|
2 |
|
3 |
import torch
|
4 |
from packaging import version
|
5 |
|
6 |
__version__ = "1.5"
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
formatter = logging.Formatter(
|
9 |
fmt="[%(asctime)s %(name)s %(levelname)s] %(message)s",
|
10 |
datefmt="%Y/%m/%d %H:%M:%S",
|
11 |
)
|
12 |
-
handler = logging.StreamHandler()
|
13 |
-
handler.setFormatter(formatter)
|
14 |
-
handler.setLevel(logging.INFO)
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
logger = logging.getLogger("hloc")
|
17 |
logger.setLevel(logging.INFO)
|
18 |
-
logger.addHandler(
|
|
|
19 |
logger.propagate = False
|
20 |
|
21 |
try:
|
|
|
1 |
import logging
|
2 |
+
import sys
|
3 |
|
4 |
import torch
|
5 |
from packaging import version
|
6 |
|
7 |
__version__ = "1.5"
|
8 |
|
9 |
+
LOG_PATH = "log.txt"
|
10 |
+
|
11 |
+
|
12 |
+
def read_logs():
|
13 |
+
sys.stdout.flush()
|
14 |
+
with open(LOG_PATH, "r") as f:
|
15 |
+
return f.read()
|
16 |
+
|
17 |
+
|
18 |
+
def flush_logs():
|
19 |
+
sys.stdout.flush()
|
20 |
+
logs = open(LOG_PATH, "w")
|
21 |
+
logs.close()
|
22 |
+
|
23 |
+
|
24 |
formatter = logging.Formatter(
|
25 |
fmt="[%(asctime)s %(name)s %(levelname)s] %(message)s",
|
26 |
datefmt="%Y/%m/%d %H:%M:%S",
|
27 |
)
|
|
|
|
|
|
|
28 |
|
29 |
+
logs_file = open(LOG_PATH, "w")
|
30 |
+
logs_file.close()
|
31 |
+
|
32 |
+
file_handler = logging.FileHandler(filename=LOG_PATH)
|
33 |
+
file_handler.setFormatter(formatter)
|
34 |
+
file_handler.setLevel(logging.INFO)
|
35 |
+
stdout_handler = logging.StreamHandler()
|
36 |
+
stdout_handler.setFormatter(formatter)
|
37 |
+
stdout_handler.setLevel(logging.INFO)
|
38 |
logger = logging.getLogger("hloc")
|
39 |
logger.setLevel(logging.INFO)
|
40 |
+
logger.addHandler(file_handler)
|
41 |
+
logger.addHandler(stdout_handler)
|
42 |
logger.propagate = False
|
43 |
|
44 |
try:
|
ui/app_class.py
CHANGED
@@ -6,6 +6,7 @@ import numpy as np
|
|
6 |
from easydict import EasyDict as edict
|
7 |
from omegaconf import OmegaConf
|
8 |
|
|
|
9 |
from ui.sfm import SfmEngine
|
10 |
from ui.utils import (
|
11 |
GRADIO_VERSION,
|
@@ -30,6 +31,11 @@ This Space demonstrates [Image Matching WebUI](https://github.com/Vincentqyw/ima
|
|
30 |
🐛 Your feedback is valuable to me. Please do not hesitate to report any bugs [here](https://github.com/Vincentqyw/image-matching-webui/issues).
|
31 |
"""
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
class ImageMatchingApp:
|
35 |
def __init__(self, server_name="0.0.0.0", server_port=7860, **kwargs):
|
@@ -52,7 +58,7 @@ class ImageMatchingApp:
|
|
52 |
return algos
|
53 |
|
54 |
def init_interface(self):
|
55 |
-
with gr.Blocks() as self.app:
|
56 |
with gr.Tab("Image Matching"):
|
57 |
with gr.Row():
|
58 |
with gr.Column(scale=1):
|
@@ -138,7 +144,7 @@ class ImageMatchingApp:
|
|
138 |
minimum=0.0,
|
139 |
maximum=1,
|
140 |
step=0.001,
|
141 |
-
label="Match
|
142 |
value=0.1,
|
143 |
)
|
144 |
match_setting_max_keypoints = gr.Slider(
|
@@ -154,7 +160,7 @@ class ImageMatchingApp:
|
|
154 |
minimum=0,
|
155 |
maximum=1,
|
156 |
step=0.001,
|
157 |
-
label="Keypoint
|
158 |
value=0.015,
|
159 |
)
|
160 |
detect_line_threshold = ( # noqa: F841
|
@@ -162,7 +168,7 @@ class ImageMatchingApp:
|
|
162 |
minimum=0.1,
|
163 |
maximum=1,
|
164 |
step=0.01,
|
165 |
-
label="Line
|
166 |
value=0.2,
|
167 |
)
|
168 |
)
|
@@ -266,6 +272,25 @@ class ImageMatchingApp:
|
|
266 |
self.display_supported_algorithms()
|
267 |
|
268 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
with gr.Accordion(
|
270 |
"Open for More: Keypoints", open=True
|
271 |
):
|
@@ -453,25 +478,7 @@ class ImageMatchingApp:
|
|
453 |
}
|
454 |
|
455 |
def _on_select_force_resize(self, visible: bool = False):
|
456 |
-
|
457 |
-
minimum=48,
|
458 |
-
maximum=2048,
|
459 |
-
step=16,
|
460 |
-
label="Image Height",
|
461 |
-
value=480,
|
462 |
-
visible=visible,
|
463 |
-
interactive=True,
|
464 |
-
)
|
465 |
-
image_width = gr.Slider(
|
466 |
-
minimum=64,
|
467 |
-
maximum=2048,
|
468 |
-
step=16,
|
469 |
-
label="Image Width",
|
470 |
-
value=640,
|
471 |
-
visible=visible,
|
472 |
-
interactive=True,
|
473 |
-
)
|
474 |
-
return image_width, image_height
|
475 |
|
476 |
def ui_reset_state(
|
477 |
self,
|
@@ -642,12 +649,7 @@ class AppSfmUI(AppBaseUI):
|
|
642 |
return gr.Textbox("not set", visible=True)
|
643 |
|
644 |
def _on_select_custom_params(self, value: bool = False):
|
645 |
-
return gr.
|
646 |
-
label="Camera Params",
|
647 |
-
value="0,0,0,0",
|
648 |
-
interactive=value,
|
649 |
-
visible=value,
|
650 |
-
)
|
651 |
|
652 |
def _init_ui(self):
|
653 |
with gr.Row():
|
|
|
6 |
from easydict import EasyDict as edict
|
7 |
from omegaconf import OmegaConf
|
8 |
|
9 |
+
from hloc import flush_logs, read_logs
|
10 |
from ui.sfm import SfmEngine
|
11 |
from ui.utils import (
|
12 |
GRADIO_VERSION,
|
|
|
31 |
🐛 Your feedback is valuable to me. Please do not hesitate to report any bugs [here](https://github.com/Vincentqyw/image-matching-webui/issues).
|
32 |
"""
|
33 |
|
34 |
+
CSS = """
|
35 |
+
#warning {background-color: #FFCCCB}
|
36 |
+
.logs_class textarea {font-size: 12px !important}
|
37 |
+
"""
|
38 |
+
|
39 |
|
40 |
class ImageMatchingApp:
|
41 |
def __init__(self, server_name="0.0.0.0", server_port=7860, **kwargs):
|
|
|
58 |
return algos
|
59 |
|
60 |
def init_interface(self):
|
61 |
+
with gr.Blocks(css=CSS) as self.app:
|
62 |
with gr.Tab("Image Matching"):
|
63 |
with gr.Row():
|
64 |
with gr.Column(scale=1):
|
|
|
144 |
minimum=0.0,
|
145 |
maximum=1,
|
146 |
step=0.001,
|
147 |
+
label="Match threshold",
|
148 |
value=0.1,
|
149 |
)
|
150 |
match_setting_max_keypoints = gr.Slider(
|
|
|
160 |
minimum=0,
|
161 |
maximum=1,
|
162 |
step=0.001,
|
163 |
+
label="Keypoint threshold",
|
164 |
value=0.015,
|
165 |
)
|
166 |
detect_line_threshold = ( # noqa: F841
|
|
|
168 |
minimum=0.1,
|
169 |
maximum=1,
|
170 |
step=0.01,
|
171 |
+
label="Line threshold",
|
172 |
value=0.2,
|
173 |
)
|
174 |
)
|
|
|
272 |
self.display_supported_algorithms()
|
273 |
|
274 |
with gr.Column():
|
275 |
+
with gr.Accordion("Open for More: Logs", open=False):
|
276 |
+
logs = gr.Textbox(
|
277 |
+
placeholder="\n" * 10,
|
278 |
+
label="Logs",
|
279 |
+
info="Verbose from inference will be displayed below.",
|
280 |
+
lines=10,
|
281 |
+
max_lines=10,
|
282 |
+
autoscroll=True,
|
283 |
+
elem_id="logs",
|
284 |
+
show_copy_button=True,
|
285 |
+
container=True,
|
286 |
+
elem_classes="logs_class",
|
287 |
+
)
|
288 |
+
self.app.load(read_logs, None, logs, every=1)
|
289 |
+
btn_clear_logs = gr.Button(
|
290 |
+
"Clear logs", elem_id="logs-button"
|
291 |
+
)
|
292 |
+
btn_clear_logs.click(flush_logs, [], [])
|
293 |
+
|
294 |
with gr.Accordion(
|
295 |
"Open for More: Keypoints", open=True
|
296 |
):
|
|
|
478 |
}
|
479 |
|
480 |
def _on_select_force_resize(self, visible: bool = False):
|
481 |
+
return gr.update(visible=visible), gr.update(visible=visible)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
482 |
|
483 |
def ui_reset_state(
|
484 |
self,
|
|
|
649 |
return gr.Textbox("not set", visible=True)
|
650 |
|
651 |
def _on_select_custom_params(self, value: bool = False):
|
652 |
+
return gr.update(visible=value)
|
|
|
|
|
|
|
|
|
|
|
653 |
|
654 |
def _init_ui(self):
|
655 |
with gr.Row():
|
ui/utils.py
CHANGED
@@ -948,9 +948,9 @@ def run_matching(
|
|
948 |
)
|
949 |
pred = match_features.match_images(matcher, pred0, pred1)
|
950 |
del extractor
|
951 |
-
gr.Info(
|
952 |
-
|
953 |
-
)
|
954 |
logger.info(f"Matching images done using: {time.time()-t1:.3f}s")
|
955 |
t1 = time.time()
|
956 |
|
|
|
948 |
)
|
949 |
pred = match_features.match_images(matcher, pred0, pred1)
|
950 |
del extractor
|
951 |
+
# gr.Info(
|
952 |
+
# f"Matching images done using: {time.time()-t1:.3f}s",
|
953 |
+
# )
|
954 |
logger.info(f"Matching images done using: {time.time()-t1:.3f}s")
|
955 |
t1 = time.time()
|
956 |
|