Skip to content

Commit

Permalink
Auto sort imports (#6)
Browse files Browse the repository at this point in the history
* Add isort, merge check runs into one

* Run isort

* Ignor build in flake8 config

* Remove jupyter as dev dependency
  • Loading branch information
sarlinpe authored Oct 9, 2023
1 parent 1709021 commit 12640af
Show file tree
Hide file tree
Showing 69 changed files with 261 additions and 248 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[flake8]
max-line-length = 88
extend-ignore = E203
exclude = .git,__pycache__,build,.venv/
21 changes: 7 additions & 14 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +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
3 changes: 3 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
python -m flake8 .
python -m isort .
python -m black .
1 change: 1 addition & 0 deletions gluefactory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging

from .utils.experiments import load_experiment # noqa: F401

formatter = logging.Formatter(
Expand Down
3 changes: 2 additions & 1 deletion gluefactory/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib.util
from .base_dataset import BaseDataset

from ..utils.tools import get_class
from .base_dataset import BaseDataset


def get_dataset(name):
Expand Down
2 changes: 1 addition & 1 deletion gluefactory/datasets/augmentations.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Union

import albumentations as A
import cv2
import numpy as np
import torch
from albumentations.pytorch.transforms import ToTensorV2
from omegaconf import OmegaConf
import cv2


class IdentityTransform(A.ImageOnlyTransform):
Expand Down
5 changes: 3 additions & 2 deletions gluefactory/datasets/base_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
See mnist.py for an example of dataset.
"""

from abc import ABCMeta, abstractmethod
import collections
import logging
from omegaconf import OmegaConf
from abc import ABCMeta, abstractmethod

import omegaconf
import torch
from omegaconf import OmegaConf
from torch.utils.data import DataLoader, Sampler, get_worker_info
from torch.utils.data._utils.collate import (
default_collate_err_msg_format,
Expand Down
10 changes: 5 additions & 5 deletions gluefactory/datasets/eth3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import logging
import os
import shutil
import zipfile
from pathlib import Path

import numpy as np
import cv2
import numpy as np
import torch
from pathlib import Path
import zipfile

from .base_dataset import BaseDataset
from .utils import scale_intrinsics
from ..geometry.wrappers import Camera, Pose
from ..settings import DATA_PATH
from ..utils.image import ImagePreprocessor, load_image
from .base_dataset import BaseDataset
from .utils import scale_intrinsics

logger = logging.getLogger(__name__)

Expand Down
14 changes: 7 additions & 7 deletions gluefactory/datasets/homographies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
from pathlib import Path

import cv2
import matplotlib.pyplot as plt
import numpy as np
import omegaconf
import torch
import matplotlib.pyplot as plt
from omegaconf import OmegaConf
from tqdm import tqdm

from .augmentations import IdentityAugmentation, augmentations
from .base_dataset import BaseDataset
from ..settings import DATA_PATH
from ..models.cache_loader import CacheLoader, pad_local_features
from ..utils.image import read_image
from ..geometry.homography import (
sample_homography_corners,
compute_homography,
sample_homography_corners,
warp_points,
)
from ..models.cache_loader import CacheLoader, pad_local_features
from ..settings import DATA_PATH
from ..utils.image import read_image
from ..utils.tools import fork_rng
from ..visualization.viz2d import plot_image_grid
from .augmentations import IdentityAugmentation, augmentations
from .base_dataset import BaseDataset

logger = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions gluefactory/datasets/hpatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import argparse
import logging
import tarfile

import matplotlib.pyplot as plt
import numpy as np
import torch
from omegaconf import OmegaConf

from .base_dataset import BaseDataset
from ..settings import DATA_PATH
from ..utils.image import load_image, ImagePreprocessor
from ..utils.image import ImagePreprocessor, load_image
from ..utils.tools import fork_rng
from ..visualization.viz2d import plot_image_grid
from .base_dataset import BaseDataset

logger = logging.getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions gluefactory/datasets/image_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Simply load images from a folder or nested folders (does not have any split).
"""

from pathlib import Path
import torch
import logging
from pathlib import Path

import omegaconf
import torch

from ..utils.image import ImagePreprocessor, load_image
from .base_dataset import BaseDataset
from ..utils.image import load_image, ImagePreprocessor


class ImageFolder(BaseDataset, torch.utils.data.Dataset):
Expand Down
9 changes: 5 additions & 4 deletions gluefactory/datasets/image_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"""

from pathlib import Path
import torch

import numpy as np
from .base_dataset import BaseDataset
from ..utils.image import load_image, ImagePreprocessor
import torch

from ..settings import DATA_PATH
from ..geometry.wrappers import Camera, Pose
from ..settings import DATA_PATH
from ..utils.image import ImagePreprocessor, load_image
from .base_dataset import BaseDataset


def names_to_pair(name0, name1, separator="/"):
Expand Down
20 changes: 8 additions & 12 deletions gluefactory/datasets/megadepth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse
import logging
from pathlib import Path
from collections.abc import Iterable
import tarfile
import shutil
import tarfile
from collections.abc import Iterable
from pathlib import Path

import h5py
import matplotlib.pyplot as plt
Expand All @@ -12,18 +12,14 @@
import torch
from omegaconf import OmegaConf

from .base_dataset import BaseDataset
from .utils import (
scale_intrinsics,
rotate_intrinsics,
rotate_pose_inplane,
)
from ..geometry.wrappers import Camera, Pose
from ..models.cache_loader import CacheLoader
from ..utils.tools import fork_rng
from ..utils.image import load_image, ImagePreprocessor
from ..settings import DATA_PATH
from ..visualization.viz2d import plot_image_grid, plot_heatmaps
from ..utils.image import ImagePreprocessor, load_image
from ..utils.tools import fork_rng
from ..visualization.viz2d import plot_heatmaps, plot_image_grid
from .base_dataset import BaseDataset
from .utils import rotate_intrinsics, rotate_pose_inplane, scale_intrinsics

logger = logging.getLogger(__name__)
scene_lists_path = Path(__file__).parent / "megadepth_scene_lists"
Expand Down
1 change: 1 addition & 0 deletions gluefactory/eval/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import torch

from ..utils.tools import get_class
from .eval_pipeline import EvalPipeline

Expand Down
25 changes: 10 additions & 15 deletions gluefactory/eval/eth3d.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
from collections import defaultdict
from pathlib import Path
from omegaconf import OmegaConf

import matplotlib.pyplot as plt
from collections import defaultdict
from tqdm import tqdm
import numpy as np
from omegaconf import OmegaConf
from tqdm import tqdm

from .io import (
parse_eval_args,
load_model,
get_eval_parser,
)

from .eval_pipeline import EvalPipeline, load_eval

from ..utils.export_predictions import export_predictions
from .utils import get_tp_fp_pts, aggregate_pr_results
from ..settings import EVAL_PATH
from ..models.cache_loader import CacheLoader
from ..datasets import get_dataset
from ..models.cache_loader import CacheLoader
from ..settings import EVAL_PATH
from ..utils.export_predictions import export_predictions
from .eval_pipeline import EvalPipeline, load_eval
from .io import get_eval_parser, load_model, parse_eval_args
from .utils import aggregate_pr_results, get_tp_fp_pts


def eval_dataset(loader, pred_file, suffix=""):
Expand Down
5 changes: 3 additions & 2 deletions gluefactory/eval/eval_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from omegaconf import OmegaConf
import numpy as np
import json

import h5py
import numpy as np
from omegaconf import OmegaConf


def load_eval(dir):
Expand Down
32 changes: 14 additions & 18 deletions gluefactory/eval/hpatches.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
from collections import defaultdict
from collections.abc import Iterable
from pathlib import Path
from omegaconf import OmegaConf
from pprint import pprint

import matplotlib.pyplot as plt
from collections import defaultdict
from collections.abc import Iterable
from tqdm import tqdm
import numpy as np
from ..visualization.viz2d import plot_cumulative
from omegaconf import OmegaConf
from tqdm import tqdm

from .io import (
parse_eval_args,
load_model,
get_eval_parser,
)
from ..utils.export_predictions import export_predictions
from ..settings import EVAL_PATH
from ..models.cache_loader import CacheLoader
from ..datasets import get_dataset
from ..models.cache_loader import CacheLoader
from ..settings import EVAL_PATH
from ..utils.export_predictions import export_predictions
from ..utils.tools import AUCMetric
from ..visualization.viz2d import plot_cumulative
from .eval_pipeline import EvalPipeline
from .io import get_eval_parser, load_model, parse_eval_args
from .utils import (
eval_homography_dlt,
eval_homography_robust,
eval_poses,
eval_matches_homography,
eval_homography_dlt,
eval_poses,
)
from ..utils.tools import AUCMetric

from .eval_pipeline import EvalPipeline


class HPatchesPipeline(EvalPipeline):
Expand Down
8 changes: 4 additions & 4 deletions gluefactory/eval/inspect.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import argparse
from collections import defaultdict
from pathlib import Path
import matplotlib.pyplot as plt
import matplotlib
from pprint import pprint
from collections import defaultdict

import matplotlib
import matplotlib.pyplot as plt

from ..settings import EVAL_PATH
from ..visualization.global_frame import GlobalFrame
from ..visualization.two_view_frame import TwoViewFrame
from . import get_benchmark
from .eval_pipeline import load_eval


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("benchmark", type=str)
Expand Down
9 changes: 5 additions & 4 deletions gluefactory/eval/io.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import pkg_resources
import argparse
from pathlib import Path
from pprint import pprint
from typing import Optional

import pkg_resources
from omegaconf import OmegaConf
import argparse
from pprint import pprint

from ..models import get_model
from ..utils.experiments import load_experiment
from ..settings import TRAINING_PATH
from ..utils.experiments import load_experiment


def parse_config_path(name_or_path: Optional[str], defaults: str) -> Path:
Expand Down
Loading

0 comments on commit 12640af

Please sign in to comment.