Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-suarez committed Oct 15, 2023
1 parent 461aac5 commit fdf4a4d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,4 @@ jobs:
- name: Test with pytest
run: |
set -o pipefail
pytest --junitxml=pytest.xml --cov=gluefactory tests/
# pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=gluefactory tests/ | tee pytest-coverage.txt
# - name: Pytest coverage comment
# uses: MishaKav/pytest-coverage-comment@main
# with:
# pytest-coverage-path: ./pytest-coverage.txt
# junitxml-path: ./pytest.xml
pytest --junitxml=pytest.xml --cov=gluefactory tests/
File renamed without changes
File renamed without changes
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ urls = {Repository = "https://github.com/cvg/glue-factory"}
[project.optional-dependencies]
extra = [
"pycolmap",
"poselib @ git+https://github.com/PoseLib/PoseLib.git",
"pytlsd @ git+https://github.com/iago-suarez/pytlsd.git",
"poselib @ git+https://github.com/PoseLib/PoseLib.git@9c8f3ca1baba69e19726cc7caded574873ec1f9e",
"pytlsd @ git+https://github.com/iago-suarez/pytlsd.git@v0.0.5",
"deeplsd @ git+https://github.com/cvg/DeepLSD.git",
"homography_est @ git+https://github.com/rpautrat/homography_est.git",
"homography_est @ git+https://github.com/rpautrat/homography_est.git@17b200d528e6aa8ac61a878a29265bf5f9d36c41",
]
dev = ["black", "flake8", "isort", "parameterized"]

Expand Down
68 changes: 40 additions & 28 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
import unittest
from collections import namedtuple
from os.path import splitext

import cv2
import matplotlib.pyplot as plt
import torch.cuda
from kornia import image_to_tensor
from omegaconf import OmegaConf
Expand All @@ -18,6 +21,11 @@
from gluefactory.utils.image import ImagePreprocessor
from gluefactory.utils.tensor import map_tensor
from gluefactory.utils.tools import set_seed
from gluefactory.visualization.viz2d import (
plot_color_line_matches,
plot_images,
plot_matches,
)


def create_input_data(cv_img0, cv_img1, device):
Expand All @@ -34,10 +42,6 @@ def create_input_data(cv_img0, cv_img1, device):
return data


def squeeze_if_tensor(t):
return torch.squeeze(t, dim=0) if isinstance(t, Tensor) else t


ExpectedResults = namedtuple("ExpectedResults", ("num_matches", "prec3px", "h_error"))


Expand All @@ -57,12 +61,15 @@ class TestIntegration(unittest.TestCase):
),
]

IMSHOWS = False

@parameterized.expand(methods_to_test)
@torch.no_grad()
def test_real_homography(self, conf_file, estimator, exp_results):
set_seed(0)
model_path = root / "gluefactory" / "configs" / conf_file
img_path0 = root / "docs" / "boat1.png"
img_path1 = root / "docs" / "boat2.png"
img_path0 = root / "assets" / "boat1.png"
img_path1 = root / "assets" / "boat2.png"
h_gt = torch.tensor(
[
[0.85799, 0.21669, 9.4839],
Expand All @@ -77,7 +84,9 @@ def test_real_homography(self, conf_file, estimator, exp_results):
cv_img0, cv_img1 = cv2.imread(str(img_path0)), cv2.imread(str(img_path1))
data = create_input_data(cv_img0, cv_img1, device)
pred = gs(data)
pred = map_tensor(pred, squeeze_if_tensor)
pred = map_tensor(
pred, lambda t: torch.squeeze(t, dim=0) if isinstance(t, Tensor) else t
)
data["H_0to1"] = h_gt.to(device)
data["H_1to0"] = torch.linalg.inv(h_gt).to(device)

Expand All @@ -93,28 +102,31 @@ def test_real_homography(self, conf_file, estimator, exp_results):
),
}

print(results)
logging.info(results)
self.assertGreater(results["num_matches"], exp_results.num_matches)
self.assertGreater(results["prec@3px"], exp_results.prec3px)
self.assertLess(results["H_error_ransac"], exp_results.h_error)

# pred = batch_to_numpy(pred)
# # pred = map_tensor(pred, lambda t: t[0].detach().cpu().numpy())
# kp0, kp1 = pred['keypoints0'], pred['keypoints1']
# m0 = pred['matches0']
# valid0 = m0 != -1
# kpm0, kpm1 = kp0[valid0], kp1[m0[valid0]]
#
# plot_images([cv_img0, cv_img1])
# plot_matches(kpm0, kpm1, a=0.0)
# plt.savefig(f'point_matches.png')
#
# lines0, lines1 = pred['lines0'], pred['lines1']
# lm0 = pred['line_matches0']
# lvalid0 = lm0 != -1
# linem0, linem1 = lines0[lvalid0], lines1[lm0[lvalid0]]
#
# plot_images([cv_img0, cv_img1])
# plot_color_line_matches([linem0, linem1])
# plt.savefig(f'line_matches.svg')
# plt.show()
if self.IMSHOWS:
pred = map_tensor(
pred, lambda t: t.cpu().numpy() if isinstance(t, Tensor) else t
)
kp0, kp1 = pred["keypoints0"], pred["keypoints1"]
m0 = pred["matches0"]
valid0 = m0 != -1
kpm0, kpm1 = kp0[valid0], kp1[m0[valid0]]

plot_images([cv_img0, cv_img1])
plot_matches(kpm0, kpm1, a=0.0)
plt.savefig(f"{splitext(conf_file)[0]}_point_matches.svg")

if "lines0" in pred and "lines1" in pred:
lines0, lines1 = pred["lines0"], pred["lines1"]
lm0 = pred["line_matches0"]
lvalid0 = lm0 != -1
linem0, linem1 = lines0[lvalid0], lines1[lm0[lvalid0]]

plot_images([cv_img0, cv_img1])
plot_color_line_matches([linem0, linem1])
plt.savefig(f"{splitext(conf_file)[0]}_line_matches.svg")
plt.show()

0 comments on commit fdf4a4d

Please sign in to comment.