Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

return all learned modules by default in eval() mode (#1266)

Dmytro Mishkin1b3e40ad2f76
diff --git a/kornia/feature/affine_shape.py b/kornia/feature/affine_shape.py
index 05f33048c..31f3da3cd 100644
--- a/kornia/feature/affine_shape.py
+++ b/kornia/feature/affine_shape.py
@@ -183,6 +183,7 @@ class LAFAffNetShapeEstimator(nn.Module):
urls['affnet'], map_location=lambda storage, loc: storage
)
self.load_state_dict(pretrained_dict['state_dict'], strict=False)
+ self.eval()
@staticmethod
def _normalize_input(x: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
diff --git a/kornia/feature/defmo.py b/kornia/feature/defmo.py
index a60c00817..d24125937 100644
--- a/kornia/feature/defmo.py
+++ b/kornia/feature/defmo.py
@@ -295,6 +295,7 @@ class DeFMO(nn.Module):
urls['defmo_rendering'], map_location=lambda storage, loc: storage
)
self.rendering.load_state_dict(pretrained_dict_ren, strict=True)
+ self.eval()
def forward(self, input_data: torch.Tensor) -> torch.Tensor:
latent = self.encoder(input_data)
diff --git a/kornia/feature/hardnet.py b/kornia/feature/hardnet.py
index 8ca4fa9f2..65398b547 100644
--- a/kornia/feature/hardnet.py
+++ b/kornia/feature/hardnet.py
@@ -66,6 +66,7 @@ class HardNet(nn.Module):
urls['liberty_aug'], map_location=lambda storage, loc: storage
)
self.load_state_dict(pretrained_dict['state_dict'], strict=True)
+ self.eval()
@staticmethod
def _normalize_input(x: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
@@ -143,6 +144,7 @@ class HardNet8(nn.Module):
urls['hardnet8v2'], map_location=lambda storage, loc: storage
)
self.load_state_dict(pretrained_dict, strict=True)
+ self.eval()
@staticmethod
def weights_init(m):
diff --git a/kornia/feature/mkd.py b/kornia/feature/mkd.py
index f35dffbaa..8d43be2b4 100644
--- a/kornia/feature/mkd.py
+++ b/kornia/feature/mkd.py
@@ -587,6 +587,7 @@ class MKDDescriptor(nn.Module):
whitening, whitening_model, in_dims=self.odims, output_dims=self.output_dims
)
self.odims = self.output_dims
+ self.eval()
def forward(self, patches: torch.Tensor) -> torch.Tensor:
if not isinstance(patches, torch.Tensor):
diff --git a/kornia/feature/orientation.py b/kornia/feature/orientation.py
index d593bcb38..4f27f8d21 100644
--- a/kornia/feature/orientation.py
+++ b/kornia/feature/orientation.py
@@ -172,6 +172,7 @@ class OriNet(nn.Module):
urls['orinet'], map_location=lambda storage, loc: storage
)
self.load_state_dict(pretrained_dict['state_dict'], strict=False)
+ self.eval()
@staticmethod
def _normalize_input(x: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
diff --git a/kornia/feature/sosnet.py b/kornia/feature/sosnet.py
index 4721ef983..762b88ba4 100644
--- a/kornia/feature/sosnet.py
+++ b/kornia/feature/sosnet.py
@@ -59,7 +59,7 @@ class SOSNet(nn.Module):
if pretrained:
pretrained_dict = torch.hub.load_state_dict_from_url(urls['lib'], map_location=lambda storage, loc: storage)
self.load_state_dict(pretrained_dict, strict=True)
-
+ self.eval()
return
def forward(self, input: torch.Tensor, eps: float = 1e-10) -> torch.Tensor:
diff --git a/kornia/feature/tfeat.py b/kornia/feature/tfeat.py
index 8265a69f8..bf094aafd 100644
--- a/kornia/feature/tfeat.py
+++ b/kornia/feature/tfeat.py
@@ -55,6 +55,7 @@ class TFeat(nn.Module):
urls['liberty'], map_location=lambda storage, loc: storage
)
self.load_state_dict(pretrained_dict, strict=True)
+ self.eval()
def forward(self, input: torch.Tensor) -> torch.Tensor:
x = self.features(input)