-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add SFD2 (CVPR 2023) and IMP (CVPR 2023) (#40)
- Loading branch information
Showing
8 changed files
with
159 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: UTF-8 -*- | ||
import sys | ||
from pathlib import Path | ||
import torchvision.transforms as tvf | ||
|
||
import torch | ||
|
||
from ..utils.base_model import BaseModel | ||
from .. import logger | ||
|
||
pram_path = Path(__file__).parent / "../../third_party/pram" | ||
sys.path.append(str(pram_path)) | ||
|
||
from nets.sfd2 import load_sfd2, extract_sfd2_return | ||
|
||
|
||
class SFD2(BaseModel): | ||
default_conf = { | ||
"max_keypoints": 4096, | ||
"model_name": 'sfd2_20230511_210205_resnet4x.79.pth', | ||
"conf_th": 0.001, | ||
|
||
} | ||
required_inputs = ["image"] | ||
|
||
def _init(self, conf): | ||
self.conf = {**self.default_conf, **conf} | ||
self.norm_rgb = tvf.Normalize( | ||
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225] | ||
) | ||
model_fn = pram_path / 'weights' / self.conf['model_name'] | ||
self.net = load_sfd2(weight_path=model_fn).cuda().eval() | ||
|
||
logger.info(f"Load SFD2 model done.") | ||
|
||
def _forward(self, data): | ||
pred = self.net.extract_local_global(data={'image': self.norm_rgb(data['image'])}, config=self.conf) | ||
out = { | ||
"keypoints": pred["keypoints"][0][None], | ||
"scores": pred["scores"][0][None], | ||
"descriptors": pred["descriptors"][0][None], | ||
} | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: UTF-8 -*- | ||
import sys | ||
from pathlib import Path | ||
|
||
import torch | ||
|
||
from ..utils.base_model import BaseModel | ||
from .. import logger | ||
|
||
pram_path = Path(__file__).parent / "../../third_party/pram" | ||
sys.path.append(str(pram_path)) | ||
|
||
from nets.gml import GML | ||
|
||
|
||
class IMP(BaseModel): | ||
default_conf = { | ||
"match_threshold": 0.2, | ||
"features": "sfd2", | ||
"model_name": "imp_gml.920.pth", | ||
'sinkhorn_iterations': 20, | ||
} | ||
required_inputs = [ | ||
"image0", | ||
"keypoints0", | ||
"scores0", | ||
"descriptors0", | ||
"image1", | ||
"keypoints1", | ||
"scores1", | ||
"descriptors1", | ||
] | ||
|
||
def _init(self, conf): | ||
self.conf = {**self.default_conf, **conf} | ||
weight_path = pram_path / "weights" / self.conf["model_name"] | ||
self.net = GML(self.conf).eval().cuda() | ||
self.net.load_state_dict(torch.load(weight_path)['model'], strict=True) | ||
logger.info(f"Load IMP model done.") | ||
|
||
def _forward(self, data): | ||
data['descriptors0'] = data['descriptors0'].transpose(2, 1).float() | ||
data['descriptors1'] = data['descriptors1'].transpose(2, 1).float() | ||
|
||
return self.net.produce_matches(data, p=0.2) |