Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/pr_test_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ jobs:
os: ['Ubuntu-latest', 'Windows-latest']
pytorch-dtype: ['float32', 'float64']

uses: kornia/workflows/.github/workflows/tests.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tests.yml@v1.11.0
with:
os: ${{ matrix.os }}
python-version: '["3.8", "3.12"]'
pytorch-version: '["1.9.1", "2.3.1"]'
pytorch-version: '["1.9.1", "2.4.0"]'
pytorch-dtype: ${{ matrix.pytorch-dtype }}

tests-cpu-macos:
uses: kornia/workflows/.github/workflows/tests.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tests.yml@v1.11.0
with:
os: 'MacOS-latest'
python-version: '["3.8", "3.12"]'
pytorch-dtype: 'float32'


coverage:
uses: kornia/workflows/.github/workflows/coverage.yml@v1.10.1
uses: kornia/workflows/.github/workflows/coverage.yml@v1.11.0

typing:
uses: kornia/workflows/.github/workflows/mypy.yml@v1.10.1
uses: kornia/workflows/.github/workflows/mypy.yml@v1.11.0

tutorials:
uses: kornia/workflows/.github/workflows/tutorials.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tutorials.yml@v1.12.1

docs:
uses: kornia/workflows/.github/workflows/docs.yml@v1.10.1
uses: kornia/workflows/.github/workflows/docs.yml@v1.11.0
with:
python-version: "3.11"

Expand All @@ -68,7 +68,7 @@ jobs:
os: ['Ubuntu-latest', 'Windows-latest'] #, 'MacOS-latest'] add it when https://github.com/pytorch/pytorch/pull/89262 be merged
pytorch-dtype: ['float32', 'float64']

uses: kornia/workflows/.github/workflows/tests.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tests.yml@v1.11.0
with:
os: ${{ matrix.os }}
pytorch-version: '["nightly"]'
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/scheduled_test_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
# os: ['Ubuntu-latest', 'Windows-latest', 'MacOS-latest']
pytorch-dtype: ['float32', 'float64']

uses: kornia/workflows/.github/workflows/tests.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tests.yml@v1.11.0
with:
os: 'Ubuntu-latest'
python-version: '["3.8", "3.9", "3.10", "3.11", "3.12"]'
pytorch-version: '["1.9.1", "1.10.2", "1.11.0", "1.12.1", "1.13.1", "2.0.1", "2.1.2", "2.2.2", "2.3.1"]'
pytorch-version: '["1.9.1", "1.10.2", "1.11.0", "1.12.1", "1.13.1", "2.0.1", "2.1.2", "2.2.2", "2.3.1", "2.4.0"]'
pytorch-dtype: ${{ matrix.pytorch-dtype }}
pytest-extra: '--runslow'

Expand All @@ -34,11 +34,11 @@ jobs:
matrix:
pytorch-dtype: ['float32', 'float64']

uses: kornia/workflows/.github/workflows/tests.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tests.yml@v1.11.0
with:
os: 'Windows-latest'
python-version: '["3.12"]'
pytorch-version: '["1.9.1", "2.3.1"]'
pytorch-version: '["1.9.1", "2.4.0"]'
pytorch-dtype: ${{ matrix.pytorch-dtype }}

tests-cpu-mac:
Expand All @@ -47,21 +47,21 @@ jobs:
matrix:
pytorch-dtype: ['float32', 'float64']

uses: kornia/workflows/.github/workflows/tests.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tests.yml@v1.11.0
with:
os: 'MacOS-latest'
pytorch-dtype: ${{ matrix.pytorch-dtype }}

coverage:
uses: kornia/workflows/.github/workflows/coverage.yml@v1.10.1
uses: kornia/workflows/.github/workflows/coverage.yml@v1.11.0

typing:
uses: kornia/workflows/.github/workflows/mypy.yml@v1.10.1
uses: kornia/workflows/.github/workflows/mypy.yml@v1.11.0

tutorials:
uses: kornia/workflows/.github/workflows/tutorials.yml@v1.10.1
uses: kornia/workflows/.github/workflows/tutorials.yml@v1.12.1

docs:
uses: kornia/workflows/.github/workflows/docs.yml@v1.10.1
uses: kornia/workflows/.github/workflows/docs.yml@v1.11.0
with:
python-version: "3.11"
3 changes: 1 addition & 2 deletions kornia/contrib/face_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from torch import nn

from kornia.geometry.bbox import nms as nms_kornia
from kornia.utils.helpers import map_location_to_cpu

__all__ = ["FaceDetector", "FaceDetectorResult", "FaceKeypoint"]

Expand Down Expand Up @@ -289,7 +288,7 @@ def __init__(self, phase: str, pretrained: bool) -> None:

# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(url, map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(url, map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict, strict=True)
self.eval()

Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/affine_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from kornia.core.check import KORNIA_CHECK_LAF, KORNIA_CHECK_SHAPE
from kornia.filters.kernels import get_gaussian_kernel2d
from kornia.filters.sobel import SpatialGradient
from kornia.utils.helpers import map_location_to_cpu

from .laf import (
ellipse_to_laf,
Expand Down Expand Up @@ -189,7 +188,7 @@ def __init__(self, pretrained: bool = False, preserve_orientation: bool = True)
self.patch_size = 32
# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["affnet"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["affnet"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict["state_dict"], strict=False)
self.preserve_orientation = preserve_orientation
if preserve_orientation:
Expand Down
4 changes: 2 additions & 2 deletions kornia/feature/dedode/dedode.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ def from_pretrained(
amp_dtype=amp_dtype,
)
model.detector.load_state_dict(
torch.hub.load_state_dict_from_url(urls["detector"][detector_weights], map_location=map_location_to_cpu)
torch.hub.load_state_dict_from_url(urls["detector"][detector_weights], map_location=torch.device("cpu"))
)
model.descriptor.load_state_dict(
torch.hub.load_state_dict_from_url(urls["descriptor"][descriptor_weights], map_location=map_location_to_cpu)
torch.hub.load_state_dict_from_url(urls["descriptor"][descriptor_weights], map_location=torch.device("cpu"))
)
model.eval()
return model
5 changes: 2 additions & 3 deletions kornia/feature/defmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from torch import nn

from kornia.core import Module, Tensor, concatenate, stack
from kornia.utils.helpers import map_location_to_cpu

urls: Dict[str, str] = {}
urls["defmo_encoder"] = "http://ptak.felk.cvut.cz/personal/rozumden/defmo_saved_models/encoder_best.pt"
Expand Down Expand Up @@ -288,11 +287,11 @@ def __init__(self, pretrained: bool = False) -> None:
# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(
urls["defmo_encoder"], map_location=map_location_to_cpu
urls["defmo_encoder"], map_location=torch.device("cpu")
)
self.encoder.load_state_dict(pretrained_dict, strict=True)
pretrained_dict_ren = torch.hub.load_state_dict_from_url(
urls["defmo_rendering"], map_location=map_location_to_cpu
urls["defmo_rendering"], map_location=torch.device("cpu")
)
self.rendering.load_state_dict(pretrained_dict_ren, strict=True)
self.eval()
Expand Down
6 changes: 3 additions & 3 deletions kornia/feature/hardnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from torch import nn

from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.utils.helpers import is_mps_tensor_safe, map_location_to_cpu
from kornia.utils.helpers import is_mps_tensor_safe

urls: Dict[str, str] = {}
urls["hardnet++"] = "https://github.com/DagnyT/hardnet/raw/master/pretrained/pretrained_all_datasets/HardNet++.pth"
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, pretrained: bool = False) -> None:

# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["liberty_aug"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["liberty_aug"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict["state_dict"], strict=True)
self.eval()

Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(self, pretrained: bool = False) -> None:

# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["hardnet8v2"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["hardnet8v2"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict, strict=True)
self.eval()

Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/hynet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from torch import nn

from kornia.core import Module, Parameter, Tensor, tensor, zeros
from kornia.utils.helpers import map_location_to_cpu

urls: Dict[str, str] = {}
urls["liberty"] = "https://github.com/ducha-aiki/Key.Net-Pytorch/raw/main/model/HyNet/weights/HyNet_LIB.pth" # pylint: disable
Expand Down Expand Up @@ -209,7 +208,7 @@ def __init__(
self.desc_norm = nn.LocalResponseNorm(2 * self.dim_desc, 2.0 * self.dim_desc, 0.5, 0.0)
# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["liberty"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["liberty"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict, strict=True)
self.eval()

Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/keynet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from kornia.core import Module, Tensor, concatenate
from kornia.filters import SpatialGradient
from kornia.geometry.transform import pyrdown
from kornia.utils.helpers import map_location_to_cpu

from .scale_space_detector import Detector_config, MultiResolutionDetector, get_default_detector_config

Expand Down Expand Up @@ -145,7 +144,7 @@ def __init__(self, pretrained: bool = False, keynet_conf: KeyNet_conf = keynet_d
)
# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(KeyNet_URL, map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(KeyNet_URL, map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict["state_dict"], strict=True)
self.eval()

Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/loftr/loftr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from kornia.core import Module, Tensor
from kornia.geometry import resize
from kornia.utils.helpers import map_location_to_cpu

from .backbone import build_backbone
from .loftr_module import FinePreprocess, LocalFeatureTransformer
Expand Down Expand Up @@ -97,7 +96,7 @@ def __init__(self, pretrained: Optional[str] = "outdoor", config: dict[str, Any]
if pretrained not in urls.keys():
raise ValueError(f"pretrained should be None or one of {urls.keys()}")

pretrained_dict = torch.hub.load_state_dict_from_url(urls[pretrained], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls[pretrained], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict["state_dict"])
self.eval()

Expand Down
5 changes: 2 additions & 3 deletions kornia/feature/mkd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from kornia.filters import GaussianBlur2d, SpatialGradient
from kornia.geometry.conversions import cart2pol
from kornia.utils import create_meshgrid
from kornia.utils.helpers import map_location_to_cpu

# Precomputed coefficients for Von Mises kernel, given N and K(appa).
sqrt2: float = 1.4142135623730951
Expand Down Expand Up @@ -534,7 +533,7 @@ def __init__(
# Load supervised(lw)/unsupervised(pca) model trained on training_set.
if self.whitening is not None:
whitening_models = torch.hub.load_state_dict_from_url(
urls[self.kernel_type], map_location=map_location_to_cpu
urls[self.kernel_type], map_location=torch.device("cpu")
)
whitening_model = whitening_models[training_set]
self.whitening_layer = Whitening(
Expand Down Expand Up @@ -582,7 +581,7 @@ def __repr__(self) -> str:


def load_whitening_model(kernel_type: str, training_set: str) -> Dict[str, Any]:
whitening_models = torch.hub.load_state_dict_from_url(urls[kernel_type], map_location=map_location_to_cpu)
whitening_models = torch.hub.load_state_dict_from_url(urls[kernel_type], map_location=torch.device("cpu"))
whitening_model = whitening_models[training_set]
return whitening_model

Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from kornia.core.check import KORNIA_CHECK_LAF, KORNIA_CHECK_SHAPE
from kornia.filters import SpatialGradient, get_gaussian_discrete_kernel1d, get_gaussian_kernel2d
from kornia.geometry import rad2deg
from kornia.utils.helpers import map_location_to_cpu

from .laf import extract_patches_from_pyramid, get_laf_orientation, set_laf_orientation

Expand Down Expand Up @@ -162,7 +161,7 @@ def __init__(self, pretrained: bool = False, eps: float = 1e-8) -> None:
self.eps = eps
# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["orinet"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["orinet"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict["state_dict"], strict=False)
self.eval()

Expand Down
4 changes: 2 additions & 2 deletions kornia/feature/sold2/sold2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.feature.sold2.structures import DetectorCfg, LineMatcherCfg
from kornia.geometry.conversions import normalize_pixel_coordinates
from kornia.utils import dataclass_to_dict, dict_to_dataclass, map_location_to_cpu
from kornia.utils import dataclass_to_dict, dict_to_dataclass

from .backbones import SOLD2Net
from .sold2_detector import LineSegmentDetectionModule, line_map_to_segments, prob_to_junctions
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, pretrained: bool = True, config: Optional[DetectorCfg] = None
# Load the pre-trained model
self.model = SOLD2Net(dataclass_to_dict(self.config))
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["wireframe"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["wireframe"], map_location=torch.device("cpu"))
state_dict = self.adapt_state_dict(pretrained_dict["model_state_dict"])
self.model.load_state_dict(state_dict)
self.eval()
Expand Down
4 changes: 2 additions & 2 deletions kornia/feature/sold2/sold2_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.feature.sold2.structures import DetectorCfg, HeatMapRefineCfg, JunctionRefineCfg, LineDetectorCfg
from kornia.geometry.bbox import nms
from kornia.utils import dataclass_to_dict, dict_to_dataclass, map_location_to_cpu, torch_meshgrid
from kornia.utils import dataclass_to_dict, dict_to_dataclass, torch_meshgrid

from .backbones import SOLD2Net

Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, pretrained: bool = True, config: Optional[DetectorCfg] = None
self.model = SOLD2Net(dataclass_to_dict(self.config))

if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["wireframe"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["wireframe"], map_location=torch.device("cpu"))
state_dict = self.adapt_state_dict(pretrained_dict["model_state_dict"])
self.model.load_state_dict(state_dict)
self.eval()
Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/sosnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from torch import nn

from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.utils.helpers import map_location_to_cpu

urls: Dict[str, str] = {}
urls["lib"] = "https://github.com/yuruntian/SOSNet/raw/master/sosnet-weights/sosnet_32x32_liberty.pth"
Expand Down Expand Up @@ -61,7 +60,7 @@ def __init__(self, pretrained: bool = False) -> None:
self.desc_norm = nn.Sequential(nn.LocalResponseNorm(256, alpha=256.0, beta=0.5, k=0.0))
# load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["lib"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["lib"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict, strict=True)
self.eval()

Expand Down
3 changes: 1 addition & 2 deletions kornia/feature/tfeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from torch import nn

from kornia.core.check import KORNIA_CHECK_SHAPE
from kornia.utils.helpers import map_location_to_cpu

urls: Dict[str, str] = {}
urls["liberty"] = "https://github.com/vbalnt/tfeat/raw/master/pretrained-models/tfeat-liberty.params" # pylint: disable
Expand Down Expand Up @@ -50,7 +49,7 @@ def __init__(self, pretrained: bool = False) -> None:
self.descr = nn.Sequential(nn.Linear(64 * 8 * 8, 128), nn.Tanh())
# use torch.hub to load pretrained model
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls["liberty"], map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(urls["liberty"], map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict, strict=True)
self.eval()

Expand Down
3 changes: 1 addition & 2 deletions kornia/filters/dexined.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from kornia.core import Module, Tensor, concatenate
from kornia.core.check import KORNIA_CHECK
from kornia.utils import map_location_to_cpu

url: str = "http://cmp.felk.cvut.cz/~mishkdmy/models/DexiNed_BIPED_10.pth"

Expand Down Expand Up @@ -221,7 +220,7 @@ def __init__(self, pretrained: bool) -> None:

def load_from_file(self, path_file: str) -> None:
# use torch.hub to load pretrained model
pretrained_dict = torch.hub.load_state_dict_from_url(path_file, map_location=map_location_to_cpu)
pretrained_dict = torch.hub.load_state_dict_from_url(path_file, map_location=torch.device("cpu"))
self.load_state_dict(pretrained_dict, strict=True)
self.eval()

Expand Down