diff --git a/.github/workflows/pr_test_cpu.yml b/.github/workflows/pr_test_cpu.yml index c9ae18d8f5c..5f8ea3342c6 100644 --- a/.github/workflows/pr_test_cpu.yml +++ b/.github/workflows/pr_test_cpu.yml @@ -20,15 +20,15 @@ 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"]' @@ -36,16 +36,16 @@ jobs: 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" @@ -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"]' diff --git a/.github/workflows/scheduled_test_cpu.yml b/.github/workflows/scheduled_test_cpu.yml index c774f6c493e..5b284639045 100644 --- a/.github/workflows/scheduled_test_cpu.yml +++ b/.github/workflows/scheduled_test_cpu.yml @@ -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' @@ -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: @@ -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" diff --git a/kornia/contrib/face_detection.py b/kornia/contrib/face_detection.py index 233e24b8525..d862d3fef04 100644 --- a/kornia/contrib/face_detection.py +++ b/kornia/contrib/face_detection.py @@ -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"] @@ -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() diff --git a/kornia/feature/affine_shape.py b/kornia/feature/affine_shape.py index b89debb100b..ceb280f6c8a 100644 --- a/kornia/feature/affine_shape.py +++ b/kornia/feature/affine_shape.py @@ -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, @@ -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: diff --git a/kornia/feature/dedode/dedode.py b/kornia/feature/dedode/dedode.py index 90c35d41d37..e1f68f2a45f 100644 --- a/kornia/feature/dedode/dedode.py +++ b/kornia/feature/dedode/dedode.py @@ -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 diff --git a/kornia/feature/defmo.py b/kornia/feature/defmo.py index bf68671b6ce..f2d314090ea 100644 --- a/kornia/feature/defmo.py +++ b/kornia/feature/defmo.py @@ -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" @@ -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() diff --git a/kornia/feature/hardnet.py b/kornia/feature/hardnet.py index da665f95710..048d58c1d5e 100644 --- a/kornia/feature/hardnet.py +++ b/kornia/feature/hardnet.py @@ -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" @@ -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() @@ -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() diff --git a/kornia/feature/hynet.py b/kornia/feature/hynet.py index 2c5fefa0e01..e198c2a4d45 100644 --- a/kornia/feature/hynet.py +++ b/kornia/feature/hynet.py @@ -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 @@ -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() diff --git a/kornia/feature/keynet.py b/kornia/feature/keynet.py index 2fae653bdcc..7e9348569e6 100644 --- a/kornia/feature/keynet.py +++ b/kornia/feature/keynet.py @@ -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 @@ -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() diff --git a/kornia/feature/loftr/loftr.py b/kornia/feature/loftr/loftr.py index d6e0c5ac9bd..3ad94d12445 100644 --- a/kornia/feature/loftr/loftr.py +++ b/kornia/feature/loftr/loftr.py @@ -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 @@ -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() diff --git a/kornia/feature/mkd.py b/kornia/feature/mkd.py index 3c1871faacd..271304dfb60 100644 --- a/kornia/feature/mkd.py +++ b/kornia/feature/mkd.py @@ -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 @@ -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( @@ -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 diff --git a/kornia/feature/orientation.py b/kornia/feature/orientation.py index 05c2361fdd2..d56f7f447a7 100644 --- a/kornia/feature/orientation.py +++ b/kornia/feature/orientation.py @@ -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 @@ -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() diff --git a/kornia/feature/sold2/sold2.py b/kornia/feature/sold2/sold2.py index 74e53f1e2dc..326230c8e4e 100644 --- a/kornia/feature/sold2/sold2.py +++ b/kornia/feature/sold2/sold2.py @@ -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 @@ -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() diff --git a/kornia/feature/sold2/sold2_detector.py b/kornia/feature/sold2/sold2_detector.py index 96a4e321475..80820a2bf36 100644 --- a/kornia/feature/sold2/sold2_detector.py +++ b/kornia/feature/sold2/sold2_detector.py @@ -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 @@ -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() diff --git a/kornia/feature/sosnet.py b/kornia/feature/sosnet.py index 0d715dc212e..9a1b15ab6d9 100644 --- a/kornia/feature/sosnet.py +++ b/kornia/feature/sosnet.py @@ -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" @@ -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() diff --git a/kornia/feature/tfeat.py b/kornia/feature/tfeat.py index 6badd4ce6e7..b70548c9ea3 100644 --- a/kornia/feature/tfeat.py +++ b/kornia/feature/tfeat.py @@ -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 @@ -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() diff --git a/kornia/filters/dexined.py b/kornia/filters/dexined.py index 3353afc33eb..2f0ca64bcda 100644 --- a/kornia/filters/dexined.py +++ b/kornia/filters/dexined.py @@ -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" @@ -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()