Content-Length: 774432 | pFad | http://github.com/cvg/limap/commit/a7bcac80c0d5b59d2aed00b2307c5aaad797f5c0

48 Fix linting for UP030 and B006 (#92) · cvg/limap@a7bcac8 · GitHub
Skip to content

Commit

Permalink
Fix linting for UP030 and B006 (#92)
Browse files Browse the repository at this point in the history
* fix B006.

* fix UP030.

* fix UP030.
  • Loading branch information
B1ueber2y authored Nov 18, 2024
1 parent 3d3c5b5 commit a7bcac8
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 36 deletions.
4 changes: 3 additions & 1 deletion limap/features/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class BaseModel(nn.Module, metaclass=ABCMeta):
required_data_keys = []
strict_conf = True

def __init__(self, conf={}):
def __init__(self, conf=None):
"""Perform some logic and call the _init method of the child model."""
if conf is None:
conf = {}
super().__init__()
default_conf = OmegaConf.merge(
OmegaConf.create(self.base_default_conf),
Expand Down
4 changes: 3 additions & 1 deletion limap/line2d/LineTR/line_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ def change_cv2_T_np(klines_cv):
return {"klines": klines, "length_klines": length, "angles": angles}


def preprocess(klines_cv, image_shape, pred_superpoint, mask=None, conf={}):
def preprocess(klines_cv, image_shape, pred_superpoint, mask=None, conf=None):
if conf is None:
conf = {}
default_conf = {
"min_length": 16,
"max_sublines": 256,
Expand Down
12 changes: 9 additions & 3 deletions limap/line2d/SOLD2/model/line_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def __init__(
line_detector_cfg,
line_matcher_cfg,
multiscale=False,
scales=[1.0, 2.0],
scales=None,
):
# Get loss weights if dynamic weighting
if scales is None:
scales = [1.0, 2.0]
_, loss_weights = get_loss_and_weights(model_cfg, device)
self.device = device

Expand Down Expand Up @@ -162,10 +164,12 @@ def multiscale_line_detection(
valid_mask=None,
desc_only=False,
profile=False,
scales=[1.0, 2.0],
scales=None,
aggregation="mean",
):
# Restrict input_image to 4D torch tensor
if scales is None:
scales = [1.0, 2.0]
if (not len(input_image.shape) == 4) or (
not isinstance(input_image, torch.Tensor)
):
Expand Down Expand Up @@ -291,8 +295,10 @@ def multiscale_line_detection(

return outputs

def __call__(self, images, valid_masks=[None, None], profile=False):
def __call__(self, images, valid_masks=None, profile=False):
# Line detection and descriptor inference on both images
if valid_masks is None:
valid_masks = [None, None]
if self.multiscale:
forward_outputs = [
self.multiscale_line_detection(
Expand Down
18 changes: 9 additions & 9 deletions limap/runners/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def setup(cfg):
folder_load = folder_save
cfg["dir_save"] = folder_save
cfg["dir_load"] = folder_load
print("[LOG] Output dir: {0}".format(cfg["dir_save"]))
print("[LOG] Loading dir: {0}".format(cfg["dir_load"]))
print("[LOG] Output dir: {}".format(cfg["dir_save"]))
print("[LOG] Loading dir: {}".format(cfg["dir_load"]))
if "weight_path" in cfg and cfg["weight_path"] is not None:
cfg["weight_path"] = os.path.expanduser(cfg["weight_path"])
print("[LOG] weight dir: {0}".format(cfg["weight_path"]))
print("[LOG] weight dir: {}".format(cfg["weight_path"]))
return cfg


Expand Down Expand Up @@ -192,15 +192,15 @@ def compute_2d_segs(cfg, imagecols, compute_descinfo=True):
weight_path = cfg.get("weight_path", None)
if "extractor" in cfg["line2d"]:
print(
"[LOG] Start 2D line detection and description (detector = {0}, extractor = {1}, n_images = {2})...".format(
"[LOG] Start 2D line detection and description (detector = {}, extractor = {}, n_images = {})...".format(
cfg["line2d"]["detector"]["method"],
cfg["line2d"]["extractor"]["method"],
imagecols.NumImages(),
)
)
else:
print(
"[LOG] Start 2D line detection and description (detector = {0}, n_images = {1})...".format(
"[LOG] Start 2D line detection and description (detector = {}, n_images = {})...".format(
cfg["line2d"]["detector"]["method"], imagecols.NumImages()
)
)
Expand Down Expand Up @@ -282,7 +282,7 @@ def compute_matches(cfg, descinfo_folder, image_ids, neighbors):
"""
weight_path = cfg.get("weight_path", None)
print(
"[LOG] Start matching 2D lines... (extractor = {0}, matcher = {1}, n_images = {2}, n_neighbors = {3})".format(
"[LOG] Start matching 2D lines... (extractor = {}, matcher = {}, n_images = {}, n_neighbors = {})".format(
cfg["line2d"]["extractor"]["method"],
cfg["line2d"]["matcher"]["method"],
len(image_ids),
Expand All @@ -294,7 +294,7 @@ def compute_matches(cfg, descinfo_folder, image_ids, neighbors):
basedir = os.path.join(
"line_matchings",
cfg["line2d"]["detector"]["method"],
"feats_{0}".format(cfg["line2d"]["extractor"]["method"]),
"feats_{}".format(cfg["line2d"]["extractor"]["method"]),
)
extractor = limap.line2d.get_extractor(
cfg["line2d"]["extractor"], weight_path=weight_path
Expand Down Expand Up @@ -333,7 +333,7 @@ def compute_exhausive_matches(cfg, descinfo_folder, image_ids):
matches_folder (str): path to store the computed matches
"""
print(
"[LOG] Start exhausive matching 2D lines... (extractor = {0}, matcher = {1}, n_images = {2})".format(
"[LOG] Start exhausive matching 2D lines... (extractor = {}, matcher = {}, n_images = {})".format(
cfg["line2d"]["extractor"]["method"],
cfg["line2d"]["matcher"]["method"],
len(image_ids),
Expand All @@ -344,7 +344,7 @@ def compute_exhausive_matches(cfg, descinfo_folder, image_ids):
basedir = os.path.join(
"line_matchings",
cfg["line2d"]["detector"]["method"],
"feats_{0}".format(cfg["line2d"]["extractor"]["method"]),
"feats_{}".format(cfg["line2d"]["extractor"]["method"]),
)
extractor = limap.line2d.get_extractor(cfg["line2d"]["extractor"])
se_match = cfg["skip_exists"] or cfg["line2d"]["matcher"]["skip_exists"]
Expand Down
4 changes: 3 additions & 1 deletion limap/runners/functions_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def compute_colmap_model_with_junctions(


def compute_2d_bipartites_from_colmap(
reconstruction, imagecols, all_2d_lines, cfg=dict()
reconstruction, imagecols, all_2d_lines, cfg=None
):
if cfg is None:
cfg = dict()
all_bpt2ds = {}
cfg_bpt2d = _structures.PL_Bipartite2dConfig(cfg)
colmap_cameras, colmap_images, colmap_points = (
Expand Down
6 changes: 3 additions & 3 deletions limap/runners/line_fitnmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def line_fitnmerge(cfg, imagecols, depths, neighbors=None, ranges=None):
##########################################################
# [C] fit 3d segments
##########################################################
fname_fit_segs = "{0}_fit_segs.npy".format(
fname_fit_segs = "{}_fit_segs.npy".format(
cfg["line2d"]["detector"]["method"]
)
if (not cfg["load_fit"]) and (
Expand Down Expand Up @@ -266,7 +266,7 @@ def line_fitnmerge(cfg, imagecols, depths, neighbors=None, ranges=None):
limapio.save_obj(
os.path.join(
cfg["dir_save"],
"fitnmerge_lines_nv{0}.obj".format(cfg["n_visible_views"]),
"fitnmerge_lines_nv{}.obj".format(cfg["n_visible_views"]),
),
VisTrack.get_lines_np(n_visible_views=cfg["n_visible_views"]),
)
Expand Down Expand Up @@ -324,7 +324,7 @@ def line_fitting_with_3Dpoints(
##########################################################
# [B] fit 3d segments
##########################################################
fname_fit_segs = "{0}_fit_segs.npy".format(
fname_fit_segs = "{}_fit_segs.npy".format(
cfg["line2d"]["detector"]["method"]
)
if (not cfg["load_fit"]) and (
Expand Down
2 changes: 1 addition & 1 deletion limap/runners/line_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def line_triangulation(cfg, imagecols, neighbors=None, ranges=None):
limapio.save_obj(
os.path.join(
cfg["dir_save"],
"triangulated_lines_nv{0}.obj".format(cfg["n_visible_views"]),
"triangulated_lines_nv{}.obj".format(cfg["n_visible_views"]),
),
VisTrack.get_lines_np(n_visible_views=cfg["n_visible_views"]),
)
Expand Down
22 changes: 15 additions & 7 deletions limap/visualize/vis_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def pyvista_vis_3d_lines(
def open3d_add_points(
w,
points,
color=[0.0, 0.0, 0.0],
color=None,
psize=1.0,
name="pcd",
ranges=None,
scale=1.0,
):
if color is None:
color = [0.0, 0.0, 0.0]
if np.array(points).shape[0] == 0:
return w
import open3d as o3d
Expand All @@ -54,11 +56,11 @@ def open3d_add_points(
return w


def open3d_get_line_set(
lines, color=[0.0, 0.0, 0.0], width=2, ranges=None, scale=1.0
):
def open3d_get_line_set(lines, color=None, width=2, ranges=None, scale=1.0):
import open3d as o3d

if color is None:
color = [0.0, 0.0, 0.0]
o3d_points, o3d_lines, o3d_colors = [], [], []
counter = 0
for line in lines:
Expand All @@ -79,14 +81,16 @@ def open3d_get_line_set(
def open3d_add_line_set(
w,
lines,
color=[0.0, 0.0, 0.0],
color=None,
width=2,
name="lineset",
ranges=None,
scale=1.0,
):
import open3d as o3d

if color is None:
color = [0.0, 0.0, 0.0]
o3d_points, o3d_lines, o3d_colors = [], [], []
counter = 0
for line in lines:
Expand All @@ -110,7 +114,7 @@ def open3d_add_line_set(

def open3d_get_cameras(
imagecols,
color=[1.0, 0.0, 0.0],
color=None,
ranges=None,
scale_cam_geometry=1.0,
scale=1.0,
Expand All @@ -119,6 +123,8 @@ def open3d_get_cameras(

import open3d as o3d

if color is None:
color = [1.0, 0.0, 0.0]
cameras = o3d.geometry.LineSet()

camera_lines = {}
Expand Down Expand Up @@ -150,7 +156,7 @@ def open3d_get_cameras(
def open3d_add_cameras(
w,
imagecols,
color=[1.0, 0.0, 0.0],
color=None,
ranges=None,
scale_cam_geometry=1.0,
scale=1.0,
Expand All @@ -159,6 +165,8 @@ def open3d_add_cameras(

import open3d as o3d

if color is None:
color = [1.0, 0.0, 0.0]
camera_lines = {}
for cam_id in imagecols.get_cam_ids():
cam = imagecols.cam(cam_id)
Expand Down
8 changes: 6 additions & 2 deletions limap/visualize/vis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ def test_line_inside_ranges(line, ranges):
return test_point_inside_ranges(line.end, ranges)


def compute_robust_range(arr, range_robust=[0.05, 0.95], k_stretch=2.0):
def compute_robust_range(arr, range_robust=None, k_stretch=2.0):
if range_robust is None:
range_robust = [0.05, 0.95]
N = arr.shape[0]
start_idx = int(round((N - 1) * range_robust[0]))
end_idx = int(round((N - 1) * range_robust[1]))
Expand All @@ -329,7 +331,9 @@ def compute_robust_range(arr, range_robust=[0.05, 0.95], k_stretch=2.0):
return start_stretched, end_stretched


def compute_robust_range_lines(lines, range_robust=[0.05, 0.95], k_stretch=2.0):
def compute_robust_range_lines(lines, range_robust=None, k_stretch=2.0):
if range_robust is None:
range_robust = [0.05, 0.95]
lines_array = np.array([line.as_array() for line in lines])
x_array = lines_array.reshape(-1, 3)[:, 0]
y_array = lines_array.reshape(-1, 3)[:, 1]
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ select = [
# isort
"I",
]
ignore = ["E501", "F401", "F403", "UP030", "B006", "B008"]
ignore = ["E501", "F401", "F403", "B008"]

[lint.per-file-ignores]
"limap/line2d/L2D2/RAL_net_cov.py" = ["SIM"]
Expand Down
2 changes: 1 addition & 1 deletion runners/eth3d/fitnmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def parse_config():
"precomputed",
"eth3d",
cfg["reso_type"],
"{0}_cam{1}".format(cfg["scene_id"], cfg["cam_id"]),
"{}_cam{}".format(cfg["scene_id"], cfg["cam_id"]),
)
return cfg

Expand Down
2 changes: 1 addition & 1 deletion runners/eth3d/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse_config():
"precomputed",
"eth3d",
cfg["reso_type"],
"{0}_cam{1}".format(cfg["scene_id"], cfg["cam_id"]),
"{}_cam{}".format(cfg["scene_id"], cfg["cam_id"]),
)
return cfg

Expand Down
2 changes: 1 addition & 1 deletion runners/rome16k/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_rome16k_triangulation(cfg, bundler_path, list_path, model_path):
if comp_id == cfg["comp_id"]:
valid_image_ids.append(img_id)
print(
"[LOG] Get image subset from component {0}: n_images = {1}".format(
"[LOG] Get image subset from component {}: n_images = {}".format(
cfg["comp_id"], len(valid_image_ids)
)
)
Expand Down
6 changes: 3 additions & 3 deletions scripts/tnt_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ def main():
# colmap align
cmd_list = []
basepath = os.path.join(colmap_output_path, scene_id, "dense")
cmd = "mkdir -p {0}".format(os.path.join(basepath, "aligned"))
cmd = "mkdir -p {}".format(os.path.join(basepath, "aligned"))
cmd_list.append(cmd)
cmd = "colmap model_aligner --input_path {0} --output_path {1} --ref_images_path {2} --robust_alignment 1 --robust_alignment_max_error {3} --transform_path {4} --ref_is_gps false".format(
cmd = "colmap model_aligner --input_path {} --output_path {} --ref_images_path {} --robust_alignment 1 --robust_alignment_max_error {} --transform_path {} --ref_is_gps false".format(
os.path.join(basepath, "sparse"),
os.path.join(basepath, "aligned"),
os.path.join(input_meta_path, scene_id, "geo_positions.txt"),
MAX_ERROR,
os.path.join(basepath, "transform.txt"),
)
cmd_list.append(cmd)
cmd = "colmap model_converter --input_path {0} --output_path {1} --output_type PLY".format(
cmd = "colmap model_converter --input_path {} --output_path {} --output_type PLY".format(
os.path.join(basepath, "aligned"),
os.path.join(basepath, "aligned/points.ply"),
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/tnt_colmap_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
cmd = f"colmap mapper --database_path {database_path} --image_path {input_folder} --output_path {sparse_folder}"
print(cmd)
os.system(cmd)
cmd = "colmap image_undistorter --image_path {0} --input_path {1} --output_path {2} --output_type COLMAP".format(
cmd = "colmap image_undistorter --image_path {} --input_path {} --output_path {} --output_type COLMAP".format(
input_folder, os.path.join(sparse_folder, "0"), dense_folder
)
print(cmd)
Expand Down

0 comments on commit a7bcac8

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/cvg/limap/commit/a7bcac80c0d5b59d2aed00b2307c5aaad797f5c0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy