Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix(feature): SOLD2_detector takes a dict config without a deprecation warning, as SOLD2 does (#6534)

Dmytro Mishkina733fe3b6248
diff --git a/changelog.d/6534.fixed.md b/changelog.d/6534.fixed.md
new file mode 100644
index 000000000..d0c257d8e
--- /dev/null
+++ b/changelog.d/6534.fixed.md
@@ -0,0 +1 @@
+`SOLD2_detector` takes a dict of `DetectorCfg` fields as `config` without a `DeprecationWarning`, as `SOLD2` does. The warning announced a removal that will not happen: plain-dict configs stay supported for both.
diff --git a/kornia/feature/sold2/sold2.py b/kornia/feature/sold2/sold2.py
index 45ef2ae95..c637a2a65 100644
--- a/kornia/feature/sold2/sold2.py
+++ b/kornia/feature/sold2/sold2.py
@@ -16,7 +16,7 @@
#
import copy
-from typing import Any, Dict, Optional, Tuple, cast
+from typing import Any, Dict, Optional, Tuple, Union, cast
import torch
import torch.nn.functional as F
@@ -71,7 +71,7 @@ class SOLD2(nn.Module):
"""
- def __init__(self, pretrained: bool = True, config: Optional[DetectorCfg] = None) -> None:
+ def __init__(self, pretrained: bool = True, config: Optional[Union[DetectorCfg, Dict[str, Any]]] = None) -> None:
if isinstance(config, dict):
config = dict_to_dataclass(cast(Dict[str, Any], config), DetectorCfg)
super().__init__()
diff --git a/kornia/feature/sold2/sold2_detector.py b/kornia/feature/sold2/sold2_detector.py
index 80757ce4a..f8f2fc4fd 100644
--- a/kornia/feature/sold2/sold2_detector.py
+++ b/kornia/feature/sold2/sold2_detector.py
@@ -16,8 +16,7 @@
#
import math
-import warnings
-from typing import Any, Dict, List, Optional, Tuple, cast
+from typing import Any, Dict, List, Optional, Tuple, Union, cast
import torch
from torch import nn
@@ -56,8 +55,8 @@ class SOLD2_detector(nn.Module):
``LineDetectorCfg``) moves each of them by at most 1 pixel per axis, in 0.25 pixel steps.
Args:
- config (DetectorCfg): Configuration object containing all parameters. None will load the default parameters,
- which are tuned for images in the range 400~800 px.
+ config (DetectorCfg): Configuration object containing all parameters, or a dict of its fields. None will load
+ the default parameters, which are tuned for images in the range 400~800 px.
pretrained (bool): If True, download and set pretrained weights to the model.
Returns:
@@ -70,15 +69,8 @@ class SOLD2_detector(nn.Module):
"""
- def __init__(self, pretrained: bool = True, config: Optional[DetectorCfg] = None) -> None:
+ def __init__(self, pretrained: bool = True, config: Optional[Union[DetectorCfg, Dict[str, Any]]] = None) -> None:
if isinstance(config, dict):
- warnings.warn(
- "Usage of config as a plain dictionary is deprecated in favor of "
- "`kornia.feature.sold2.structures.DetectorCfg`. The support of plain "
- "dictionaries as config will be removed in a future release.",
- category=DeprecationWarning,
- stacklevel=2,
- )
config = dict_to_dataclass(cast(Dict[str, Any], config), DetectorCfg)
super().__init__()
# Initialize some parameters
diff --git a/tests/feature/test_sold2.py b/tests/feature/test_sold2.py
index e447c1b3c..ba23bee30 100644
--- a/tests/feature/test_sold2.py
+++ b/tests/feature/test_sold2.py
@@ -15,6 +15,8 @@
# limitations under the License.
#
+import warnings
+
import pytest
import torch
import torch.nn.functional as F
@@ -258,6 +260,16 @@ class TestSOLD2(BaseTester):
assert cfg.use_descriptor is False
assert detector.config.use_descriptor is False
+ def test_detector_config_dict_is_accepted_without_a_warning(self):
+ # SOLD2 takes a dict of DetectorCfg fields silently; its detector-only sibling takes one the same way.
+ cfg = {"grid_size": 4}
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", DeprecationWarning)
+ detector = SOLD2_detector(pretrained=False, config=cfg)
+ assert cfg == {"grid_size": 4}
+ assert detector.config.grid_size == 4
+ assert detector.config.use_descriptor is False
+
def test_match_keeps_torch_diag_5722(self, device, dtype):
sold2 = SOLD2(pretrained=False).to(device, dtype).eval()
diag = torch.diag