diff --git a/.flake8 b/.flake8 index 8dd399a..899119f 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,4 @@ [flake8] max-line-length = 88 extend-ignore = E203 +exclude = .git,__pycache__,build,.venv/ diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 45622b3..368b225 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -8,23 +8,17 @@ on: pull_request: types: [ assigned, opened, synchronize, reopened ] jobs: - formatting-check: - name: Formatting Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: psf/black@stable - with: - jupyter: true - linting-check: - name: Linting Check + check: + name: Format and Lint Checks runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: '3.10' + cache: 'pip' - run: python -m pip install --upgrade pip - - run: python -m pip install . - - run: python -m pip install --upgrade flake8 - - run: python -m flake8 . --exclude build/ + - run: python -m pip install .[dev] + - run: python -m flake8 . + - run: python -m isort . --check-only --diff + - run: python -m black . --check --diff diff --git a/.gitignore b/.gitignore index 2acf4eb..4bce5dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,166 @@ -/build/ -*.egg-info -*.pyc -/.idea/ /data/ /outputs/ -__pycache__ /lightglue/weights/ -lightglue/_flash/ *-checkpoint.ipynb *.pth + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ diff --git a/benchmark.py b/benchmark.py index f7e149b..088b30e 100644 --- a/benchmark.py +++ b/benchmark.py @@ -1,15 +1,16 @@ # Benchmark script for LightGlue on real images -from pathlib import Path import argparse -import matplotlib.pyplot as plt -from collections import defaultdict import time +from collections import defaultdict +from pathlib import Path + +import matplotlib.pyplot as plt import numpy as np import torch +import torch._dynamo from lightglue import LightGlue, SuperPoint from lightglue.utils import load_image -import torch._dynamo torch.set_grad_enabled(False) diff --git a/lightglue/__init__.py b/lightglue/__init__.py index 20efa8b..7a20d06 100644 --- a/lightglue/__init__.py +++ b/lightglue/__init__.py @@ -1,4 +1,4 @@ +from .disk import DISK # noqa from .lightglue import LightGlue # noqa from .superpoint import SuperPoint # noqa -from .disk import DISK # noqa from .utils import match_pair # noqa diff --git a/lightglue/disk.py b/lightglue/disk.py index c74d4fd..9632578 100644 --- a/lightglue/disk.py +++ b/lightglue/disk.py @@ -1,7 +1,9 @@ +from types import SimpleNamespace + +import kornia import torch import torch.nn as nn -import kornia -from types import SimpleNamespace + from .utils import ImagePreprocessor diff --git a/lightglue/lightglue.py b/lightglue/lightglue.py index ac76003..9ddcda4 100644 --- a/lightglue/lightglue.py +++ b/lightglue/lightglue.py @@ -1,11 +1,12 @@ +import warnings from pathlib import Path from types import SimpleNamespace -import warnings +from typing import Callable, List, Optional, Tuple + import numpy as np import torch -from torch import nn import torch.nn.functional as F -from typing import Optional, List, Callable, Tuple +from torch import nn try: from flash_attn.modules.mha import FlashCrossAttention diff --git a/lightglue/superpoint.py b/lightglue/superpoint.py index 8529f07..999df9e 100644 --- a/lightglue/superpoint.py +++ b/lightglue/superpoint.py @@ -44,6 +44,7 @@ import torch from torch import nn + from .utils import ImagePreprocessor diff --git a/lightglue/utils.py b/lightglue/utils.py index e8d3080..ab7fc0e 100644 --- a/lightglue/utils.py +++ b/lightglue/utils.py @@ -1,11 +1,12 @@ +import collections.abc as collections from pathlib import Path -import torch -import kornia +from types import SimpleNamespace +from typing import Callable, List, Optional, Tuple, Union + import cv2 +import kornia import numpy as np -from typing import Union, List, Optional, Callable, Tuple -import collections.abc as collections -from types import SimpleNamespace +import torch class ImagePreprocessor: diff --git a/lightglue/viz2d.py b/lightglue/viz2d.py index 4999a76..22dc3f6 100644 --- a/lightglue/viz2d.py +++ b/lightglue/viz2d.py @@ -6,8 +6,8 @@ """ import matplotlib -import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects +import matplotlib.pyplot as plt import numpy as np import torch diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6e3bf20 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,30 @@ +[project] +name = "lightglue" +description = "LightGlue: Local Feature Matching at Light Speed" +version = "0.0" +authors = [ + {name = "Philipp Lindenberger"}, + {name = "Paul-Edouard Sarlin"}, +] +readme = "README.md" +requires-python = ">=3.6" +license = {file = "LICENSE"} +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", +] +urls = {Repository = "https://github.com/cvg/LightGlue/"} +dynamic = ["dependencies"] + +[project.optional-dependencies] +dev = ["black", "flake8", "isort"] + +[tool.setuptools] +packages = ["lightglue"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.isort] +profile = "black" diff --git a/setup.py b/setup.py deleted file mode 100644 index 2b012e9..0000000 --- a/setup.py +++ /dev/null @@ -1,27 +0,0 @@ -from pathlib import Path -from setuptools import setup - -description = ["LightGlue"] - -with open(str(Path(__file__).parent / "README.md"), "r", encoding="utf-8") as f: - readme = f.read() -with open(str(Path(__file__).parent / "requirements.txt"), "r") as f: - dependencies = f.read().split("\n") - -setup( - name="lightglue", - version="0.0", - packages=["lightglue"], - python_requires=">=3.6", - install_requires=dependencies, - author="Philipp Lindenberger, Paul-Edouard Sarlin", - description=description, - long_description=readme, - long_description_content_type="text/markdown", - url="https://github.com/cvg/LightGlue/", - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - ], -)