Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

chore (CI): ensure support to torch 2.4 (#2972)

João G. Atkinson A.ac99883573fb
diff --git a/.github/workflows/pr_test_cpu.yml b/.github/workflows/pr_test_cpu.yml
index d5f1acbe6..dc5b2a826 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/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
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/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
with:
os: 'MacOS-latest'
python-version: '["3.8", "3.12"]'
@@ -36,16 +36,16 @@ jobs:
coverage:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
typing:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
tutorials:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
docs:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
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/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
with:
os: ${{ matrix.os }}
pytorch-version: '["nightly"]'
diff --git a/.github/workflows/scheduled_test_cpu.yml b/.github/workflows/scheduled_test_cpu.yml
index 305ecdc27..d8896f74b 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/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
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/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
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/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
with:
os: 'MacOS-latest'
pytorch-dtype: ${{ matrix.pytorch-dtype }}
coverage:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
typing:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
tutorials:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
docs:
- uses: kornia/workflows/.github/workflows/[email protected]
+ uses: kornia/workflows/.github/workflows/[email protected]
with:
python-version: '["3.11"]'
diff --git a/kornia/contrib/face_detection.py b/kornia/contrib/face_detection.py
index 233e24b85..d862d3fef 100644
--- a/kornia/contrib/face_detection.py
+++ b/kornia/contrib/face_detection.py
@@ -8,7 +8,6 @@ import torch.nn.functional as F
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 @@ class YuFaceDetectNet(nn.Module):
# 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 b89debb10..ceb280f6c 100644
--- a/kornia/feature/affine_shape.py
+++ b/kornia/feature/affine_shape.py
@@ -8,7 +8,6 @@ from torch import nn
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 @@ class LAFAffNetShapeEstimator(nn.Module):
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 2d8f899b9..91c343bf8 100644
--- a/kornia/feature/dedode/dedode.py
+++ b/kornia/feature/dedode/dedode.py
@@ -198,10 +198,10 @@ class DeDoDe(Module):
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 bf68671b6..f2d314090 100644
--- a/kornia/feature/defmo.py
+++ b/kornia/feature/defmo.py
@@ -4,7 +4,6 @@ import torch
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 @@ class DeFMO(Module):
# 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 da665f957..048d58c1d 100644
--- a/kornia/feature/hardnet.py
+++ b/kornia/feature/hardnet.py
@@ -5,7 +5,7 @@ import torch.nn.functional as F
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 @@ class HardNet(nn.Module):
# 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 @@ class HardNet8(nn.Module):
# 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 2c5fefa0e..e198c2a4d 100644
--- a/kornia/feature/hynet.py
+++ b/kornia/feature/hynet.py
@@ -4,7 +4,6 @@ import torch
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 @@ class HyNet(Module):
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 2fae653bd..7e9348569 100644
--- a/kornia/feature/keynet.py
+++ b/kornia/feature/keynet.py
@@ -8,7 +8,6 @@ from typing_extensions import TypedDict
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 @@ class KeyNet(Module):
)
# 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 d6e0c5ac9..3ad94d124 100644
--- a/kornia/feature/loftr/loftr.py
+++ b/kornia/feature/loftr/loftr.py
@@ -6,7 +6,6 @@ import torch
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 @@ class LoFTR(Module):
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 3c1871faa..271304dfb 100644
--- a/kornia/feature/mkd.py
+++ b/kornia/feature/mkd.py
@@ -9,7 +9,6 @@ from kornia.core import Tensor, cos, sin, tensor, zeros
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 @@ class MKDDescriptor(nn.Module):
# 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 @@ class MKDDescriptor(nn.Module):
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 05c2361fd..d56f7f447 100644
--- a/kornia/feature/orientation.py
+++ b/kornia/feature/orientation.py
@@ -8,7 +8,6 @@ from kornia.constants import pi
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 @@ class OriNet(nn.Module):
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 74e53f1e2..326230c8e 100644
--- a/kornia/feature/sold2/sold2.py
+++ b/kornia/feature/sold2/sold2.py
@@ -8,7 +8,7 @@ from kornia.core import Module, Tensor, concatenate, pad, stack
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 @@ class SOLD2(Module):
# 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 96a4e3214..80820a2bf 100644
--- a/kornia/feature/sold2/sold2_detector.py
+++ b/kornia/feature/sold2/sold2_detector.py
@@ -8,7 +8,7 @@ from kornia.core import Module, Tensor, concatenate, sin, stack, tensor, where,
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 @@ class SOLD2_detector(Module):
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 0d715dc21..9a1b15ab6 100644
--- a/kornia/feature/sosnet.py
+++ b/kornia/feature/sosnet.py
@@ -4,7 +4,6 @@ import torch
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 @@ class SOSNet(nn.Module):
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 6badd4ce6..b70548c9e 100644
--- a/kornia/feature/tfeat.py
+++ b/kornia/feature/tfeat.py
@@ -4,7 +4,6 @@ import torch
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 @@ class TFeat(nn.Module):
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 0c83ff4ac..d28d3f693 100644
--- a/kornia/filters/dexined.py
+++ b/kornia/filters/dexined.py
@@ -12,7 +12,6 @@ from torch import nn
from kornia.core import ImageModule as Module
from kornia.core import 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"
@@ -222,7 +221,7 @@ class DexiNed(Module):
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()