From 3d826b691937140e52c421ef7de7d05b276cc150 Mon Sep 17 00:00:00 2001 From: Mihai Dusmanu Date: Tue, 12 Jul 2022 11:44:12 +0200 Subject: [PATCH 1/2] Initial version. --- hloc/extract_features.py | 15 +++++++++++++++ hloc/extractors/msretrieval.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 hloc/extractors/msretrieval.py diff --git a/hloc/extract_features.py b/hloc/extract_features.py index 1713f320..19fd237d 100644 --- a/hloc/extract_features.py +++ b/hloc/extract_features.py @@ -123,6 +123,21 @@ 'output': 'global-feats-openibl', 'model': {'name': 'openibl'}, 'preprocessing': {'resize_max': 1024}, + }, + 'dir-ms': { + 'output': 'global-feats-dir-ms', + 'model': {'name': 'msretrieval', 'backbone': {'name': 'dir'}}, + 'preprocessing': {'resize_max': 1024}, + }, + 'netvlad-ms': { + 'output': 'global-feats-netvlad-ms', + 'model': {'name': 'msretrieval', 'backbone': {'name': 'netvlad'}}, + 'preprocessing': {'resize_max': 1024}, + }, + 'openibl-ms': { + 'output': 'global-feats-openibl-ms', + 'model': {'name': 'msretrieval', 'backbone': {'name': 'openibl'}}, + 'preprocessing': {'resize_max': 1024}, } } diff --git a/hloc/extractors/msretrieval.py b/hloc/extractors/msretrieval.py new file mode 100644 index 00000000..cba31604 --- /dev/null +++ b/hloc/extractors/msretrieval.py @@ -0,0 +1,32 @@ +import kornia +import torch +import torch.nn.functional as F + +from ..utils.base_model import BaseModel, dynamic_load +from .. import extractors + + +class MultiscaleRetrieval(BaseModel): + default_conf = { + 'scales': [1.41, 1.0, 0.71] + } + + def _init(self, conf): + self.scales = conf['scales'] + assert 'backbone' in conf + Backbone = dynamic_load(extractors, conf['backbone']['name']) + self.backbone = Backbone(conf['backbone']) + + def _forward(self, data): + input_image = data['image'] + + global_descs = [] + for scale in self.scales: + image = kornia.geometry.rescale(input_image, (scale, scale), antialias=True) + global_descs.append(self.backbone({'image': image})['global_descriptor']) + global_desc = torch.mean(torch.stack(global_descs, dim=0), dim=0) + global_desc = F.normalize(global_desc, dim=1) + + return { + 'global_descriptor': global_desc + } \ No newline at end of file From 07009d4d6b61eb82cbe5ddbb4cce26488dc5f034 Mon Sep 17 00:00:00 2001 From: Mihai Dusmanu Date: Tue, 12 Jul 2022 11:47:14 +0200 Subject: [PATCH 2/2] fix. --- hloc/extractors/msretrieval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hloc/extractors/msretrieval.py b/hloc/extractors/msretrieval.py index cba31604..7f640329 100644 --- a/hloc/extractors/msretrieval.py +++ b/hloc/extractors/msretrieval.py @@ -29,4 +29,4 @@ def _forward(self, data): return { 'global_descriptor': global_desc - } \ No newline at end of file + }