Code for the CVPR2021 paper "Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition"

Overview

Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition

License: MIT stars GitHub issues GitHub closed issues GitHub repo size QUT Centre for Robotics

PWC PWC PWC PWC PWC PWC

This repository contains code for the CVPR2021 paper "Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition"

The article can be found on arXiv and the official proceedings.

Patch-NetVLAD method diagram

License + attribution/citation

When using code within this repository, please refer the following paper in your publications:

@inproceedings{hausler2021patchnetvlad,
  title={Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition},
  author={Hausler, Stephen and Garg, Sourav and Xu, Ming and Milford, Michael and Fischer, Tobias},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={14141--14152},
  year={2021}
}

The code is licensed under the MIT License.

Installation

We recommend using conda (or better: mamba) to install all dependencies. If you have not yet installed conda/mamba, please download and install mambaforge.

conda create -n patchnetvlad python=3.8 numpy pytorch-gpu torchvision natsort tqdm opencv pillow scikit-learn faiss matplotlib-base -c conda-forge

conda activate patchnetvlad

We provide several pre-trained models and configuration files. The pre-trained models will be downloaded automatically into the pretrained_models the first time feature extraction is performed.

Alternatively, you can manually download the pre-trained models into a folder of your choice; click to expand if you want to do so.

We recommend downloading the models into the pretrained_models folder (which is setup in the config files within the configs directory):

# Note: the pre-trained models will be downloaded automatically the first time feature extraction is performed
# the steps below are optional!

# You can use the download script which automatically downloads the models:
python ./download_models.py

# Manual download:
cd pretrained_models
wget -O mapillary_WPCA128.pth.tar https://cloudstor.aarnet.edu.au/plus/s/vvr0jizjti0z2LR/download
wget -O mapillary_WPCA512.pth.tar https://cloudstor.aarnet.edu.au/plus/s/DFxbGgFwh1y1wAz/download
wget -O mapillary_WPCA4096.pth.tar https://cloudstor.aarnet.edu.au/plus/s/ZgW7DMEpeS47ELI/download
wget -O pittsburgh_WPCA128.pth.tar https://cloudstor.aarnet.edu.au/plus/s/2ORvaCckitjz4Sd/download
wget -O pittsburgh_WPCA512.pth.tar https://cloudstor.aarnet.edu.au/plus/s/WKl45MoboSyB4SH/download
wget -O pittsburgh_WPCA4096.pth.tar https://cloudstor.aarnet.edu.au/plus/s/1aoTGbFjsekeKlB/download

If you want to use the shortcuts patchnetvlad-match-two, patchnetvlad-feature-match and patchnetvlad-feature-extract, you also need to run (which also lets you use Patch-NetVLAD in a modular way):

pip3 install --no-deps -e .

Quick start

Feature extraction

Replace performance.ini with speed.ini or storage.ini if you want, and adapt the dataset paths - examples are given for the Pittsburgh30k dataset (simply replace pitts30k with tokyo247 or nordland for these datasets).

python feature_extract.py \
  --config_path patchnetvlad/configs/performance.ini \
  --dataset_file_path=pitts30k_imageNames_index.txt \
  --dataset_root_dir=/path/to/your/pitts/dataset \
  --output_features_dir patchnetvlad/output_features/pitts30k_index

Repeat for the query images by replacing _index with _query. Note that you have to adapt dataset_root_dir.

Feature matching (dataset)

python feature_match.py \
  --config_path patchnetvlad/configs/performance.ini \
  --dataset_root_dir=/path/to/your/pitts/dataset \
  --query_file_path=pitts30k_imageNames_query.txt \
  --index_file_path=pitts30k_imageNames_index.txt \
  --query_input_features_dir patchnetvlad/output_features/pitts30k_query \
  --index_input_features_dir patchnetvlad/output_features/pitts30k_index \
  --ground_truth_path patchnetvlad/dataset_gt_files/pitts30k_test.npz \
  --result_save_folder patchnetvlad/results/pitts30k

Note that providing ground_truth_path is optional.

This will create three output files in the folder specified by result_save_folder:

  • recalls.txt with a plain text output (only if ground_truth_path is specified)
  • NetVLAD_predictions.txt with top 100 reference images for each query images obtained using "vanilla" NetVLAD in Kapture format
  • PatchNetVLAD_predictions.txt with top 100 reference images from above re-ranked by Patch-NetVLAD, again in Kapture format

Feature matching (two files)

python match_two.py \
--config_path patchnetvlad/configs/performance.ini \
--first_im_path=patchnetvlad/example_images/tokyo_query.jpg \
--second_im_path=patchnetvlad/example_images/tokyo_db.png

We provide the match_two.py script which computes the Patch-NetVLAD features for two given images and then determines the local feature matching between these images. While we provide example images, any image pair can be used.

The script will print a score value as an output, where a larger score indicates more similar images and a lower score means dissimilar images. The function also outputs a matching figure, showing the patch correspondances (after RANSAC) between the two images. The figure is saved as results/patchMatchings.png.

FAQ

Patch-NetVLAD qualitative results

How to Create New Ground Truth Files

We provide three ready-to-go ground truth files in the dataset_gt_files folder, however, for evaluation on other datasets you will need to create your own .npz ground truth data files. Each .npz stores three variables: utmQ (a numpy array of floats), utmDb (a numpy array of floats) and posDistThr (a scalar numpy float).

Each successive element within utmQ and utmDb needs to correspond to the corresponding row of the image list file. posDistThr is the ground truth tolerance value (typically in meters).

The following mock example details the steps required to create a new ground truth file:

  1. Collect GPS data for your query and database traverses and convert to utm format. Ensure the data is sampled at the same rate as your images.
  2. Select your own choice of posDistThr value.
  3. Save these variables using Numpy, such as this line of code: np.savez('dataset_gt_files/my_dataset.npz', utmQ=my_utmQ, utmDb=my_utmDb, posDistThr=my_posDistThr)

Acknowledgements

We would like to thank Gustavo Carneiro, Niko Suenderhauf and Mark Zolotas for their valuable comments in preparing this paper. This work received funding from the Australian Government, via grant AUSMURIB000001 associated with ONR MURI grant N00014-19-1-2571. The authors acknowledge continued support from the Queensland University of Technology (QUT) through the Centre for Robotics.

Related works

Please check out this collection of related works on place recognition.

Comments
  • Fixing val.py incorrect recalls issue #43

    Fixing val.py incorrect recalls issue #43

    Made changes to val.py that should fix the indices issue that was causing low reported recalls for mapillary validation on the cph and sf datasets. Without PCA, the recalls with NetVLAD (with the mapillary trained model) are now: 0.495, 0.65, 0.718, 0.77, 0.83, 0.868.

    opened by StephenHausler 10
  • About the result on Mapillary

    About the result on Mapillary

    Thank you for this nice code base and paper. I am trying to reproduce the result on Mapillary following the training from scratch instruction. However, after training for multiple weeks, the result is still extremely low: image

    Is the result before PCAW supposed to be like this? Or maybe there is something wrong? I just follow the instruction: python train.py
    --config_path patchnetvlad/configs/train.ini
    --cache_path=/path/to/your/desired/cache/folder
    --save_path=/path/to/your/desired/checkpoint/save/folder
    --dataset_root_dir=/path/to/your/mapillary/dataset And there is no error reported. Thank you so much for your time. Looking forward to hearing from you.

    opened by Jeff-Zilence 9
  • Downloading Nordland dataset

    Downloading Nordland dataset

    Hi, will you release your version of the Nordland dataset? It would be great to have the chance to download the dataset directly, as it would avoid possible inconsistencies. Also, there shouldn't be any legal issue given that it is licensed under Creative Commons :-)

    opened by gmberton 6
  • permission for loading the model [certificate verify failed]

    permission for loading the model [certificate verify failed]

    hi :) I installed all packages and tried to run "match_two.py" file. for loading Auto-download pretrained models, it asked me so I type "YES" but i got a error message. [certificate verify failed]

    I am using Window PC, please let me know how to solve this. thanks

    image

    opened by jaaaaaang 6
  • Reproduce results of NetVLAD on RobotCar Seasons v2

    Reproduce results of NetVLAD on RobotCar Seasons v2

    @Tobias-Fischer @oravus Hi,first,I really appreciate for your work. I'm trying to reproduce results of NetVLAD on RobotCar Seasons v2 in the Table 1 and Supplementary Table 1,but encountered some problems.I have extracted the global descriptor using Netvlad with netvlad_extract.ini.May I ask if it is convenient to supplement the subsequent code to facilitate the reoccurrence work?Perhaps it would be better to have detailed instructions. I am always looking forward to your kind response. Best regards.

    opened by MAX-OTW 5
  • question about training loss

    question about training loss

    Hi, I really appreciate for the work! It is helpful for me to try it with your instructions. But I have a question about training. I try to retrain the network (with original Vgg16 backbone or change it to ResNet18, cropped it properly and maintain most of the parameters as the pretrained weights). I found that the loss went down rapidly at the first epoch and almost reach to 0.00. Would you describe the change of your loss when you train this network? Thank you very much!

    Best regards

    opened by LyyyyyyyN 5
  • how to use pool=patchnetvlad to train the network

    how to use pool=patchnetvlad to train the network

    Dear,

    Thank you for the great job!

    I got a question about how to use the output of patchnetvlad to train the network while vlad_local and vlad_global are generated at the same time. is it OK to use the vlad_global feature to estimate the triplet loss?

    Best, Qiang

    opened by zhaiqx 5
  • Question about “posDistThr” of the Nordland dataset

    Question about “posDistThr” of the Nordland dataset

    Hi, thanks for your work. I have a question about “posDistThr” of Nordland dataset. This repository sets the utm coordinate of i-th frame to (i,i) in the Nordland.npz file, which allows us to have a consistent function for evaluating [email protected] for all datasets. It's great! The tolerance for Nordland dataset is 10 frames in the Patch-NetVLAD paper. However, the radius of the first frame (0,0) to the 11-th frame (10,10) is 10sqrt(2) rather than 10. The “posDistThr” is set to 10 in Nordland.npz file in this repository. I have wrote a script to calculate [email protected] on Nordland (tolerance is 2 frames). The result is consistent with setting the “posDistThr” to 2sqrt(2) rather than 2.

    opened by Lu-Feng 4
  • Reproduce the results of DELG in the paper

    Reproduce the results of DELG in the paper

    Hi, thank you for sharing this great work. In the official paper, DELG achieves the top performance on some datasets. May I know how to reproduce those results of DELG? Do you use the pre-trained model or fine-tune it on Pitts30k/MSLS?

    opened by hellocasper 4
  • Incorrect Aachen Day-Night result

    Incorrect Aachen Day-Night result

    Hi, I tried to use your pretrained pittsburgh_WPCA4096 model to test on Aachen Day-Night dataset, but got totally incorrect result. here is my complete process.

    1. generate Aachen_db_path.txt and Aachen_query_path.txt

    2. run the feature_extract.py for db and query images use following two commands.

    python feature_extract.py \
      --config_path patchnetvlad/configs/speed.ini \
      --dataset_file_path=Aachen_db_path.txt \
      --output_features_dir patchnetvlad/output_features/aachen_index
    
    python feature_extract.py \
      --config_path patchnetvlad/configs/speed.ini \
      --dataset_file_path=Aachen_query_path.txt \
      --output_features_dir patchnetvlad/output_features/aachen_query
    
    1. run the 'feture_match.py' for feature matching without providing ground_truth_path
    python feature_match.py \
      --config_path patchnetvlad/configs/speed.ini \
      --query_file_path=Aachen_query_path.txt \
      --index_file_path=Aachen_db_path.txt \
      --query_input_features_dir patchnetvlad/output_features/aachen_query \
      --index_input_features_dir patchnetvlad/output_features/aachen_index \
      --result_save_folder patchnetvlad/results/aachen_subset
    
    1. then process PatchNetVLAD_predictions.txt, for each query image it output top 100 reference images. I just used the pose of top1 reference image as the estimated pose of each query image and post the result to benchmark, but got totally wrong result. here is the result:

    image

    I want to know what's wrong with my steps and why it outputs such unacceptable results. Is the model version that I used is wrong? Or have you test your models on Aachen dataset, if you did, could you please provide the result ?

    opened by HeartbreakSurvivor 4
  • About RobotCar v2 results

    About RobotCar v2 results

    Hi, I really appreciate for your work. I'm trying to reproduce your result on RobotCar seasons v2 dataset and encountered some problems. Which dataset split is used in the Tables 1 and 2 of the main paper, test or train? Besides, are these results integrate ALL conditions including day and night?

    I noticed that the Suppl. Table 1. reports results for each condition obtained from the training split. But when I tried to summary these results in Suppl. Table 1. using statistics on the train query set, I failed to obtain the results in the Tables 1 of the main paper. So I'm a bit confused about the dataset settings.

    I am always looking forward to your kind response.

    Best regards,

    opened by RuotongWANG 4
  • Can't reproduce Robotcar results

    Can't reproduce Robotcar results

    Hi, I tried to reproduce your result on Robotcar Seasons V2 test set by submitting to the challenge submission server. I used the released performance-focused model which is pre-trained on MSLS dataset, but I got this incorrect result: image And I tried the model pre-trained on Pitts30k, the results are not correct either. image Besides, the results on other datasets is normal. Is the model version that I used is wrong? Could you possibly release the model state that achieves the results on Robotcat dataset shown in the paper? Or would you provide the results on test set split by conditions like the Supplementary Table 1? Thank you so much.

    Best regards,

    opened by RuotongWANG 11
  • Train on custom dataset

    Train on custom dataset

    Hi, I really appreciate for the work you've done. I wondered if the training code will be released, which can be used to train our custom dataset, thanks.

    Best regards.

    opened by JiananZhao0224 14
Releases(v0.1.6)
  • v0.1.6(Nov 11, 2021)

    Training code

    This release adds code to train NetVLAD on the Mapillary dataset + PCAing models using either Mapillary dataset or Pittsburgh (https://github.com/QVPR/Patch-NetVLAD/pull/20 and https://github.com/QVPR/Patch-NetVLAD/pull/39)

    Bugfixes

    • Support for Multi-GPU inference (https://github.com/QVPR/Patch-NetVLAD/pull/22 - thanks @michaelschleiss)
    • Fix in keypoint positions (https://github.com/QVPR/Patch-NetVLAD/commit/6005b555cf05414afac3f3c0203e22a249d05b91)
    • Fix recalls when validating on Mapillary dataset (https://github.com/QVPR/Patch-NetVLAD/pull/44)

    Full Changelog: https://github.com/QVPR/Patch-NetVLAD/compare/v0.1.5...v0.1.6

    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Jun 22, 2021)

  • v0.1.4(Jun 11, 2021)

  • v0.1.2(Jun 2, 2021)

  • v0.1.1(Jun 2, 2021)

Owner
QVPR
QVPR
Implementation of ETSformer, state of the art time-series Transformer, in Pytorch

ETSformer - Pytorch Implementation of ETSformer, state of the art time-series Transformer, in Pytorch Install $ pip install etsformer-pytorch Usage im

Phil Wang 121 Dec 30, 2022
Instance Semantic Segmentation List

Instance Semantic Segmentation List This repository contains lists of state-or-art instance semantic segmentation works. Papers and resources are list

bighead 87 Mar 06, 2022
This repository contains the code for the paper ``Identifiable VAEs via Sparse Decoding''.

Sparse VAE This repository contains the code for the paper ``Identifiable VAEs via Sparse Decoding''. Data Sources The datasets used in this paper wer

Gemma Moran 17 Dec 12, 2022
Vector Quantization, in Pytorch

Vector Quantization - Pytorch A vector quantization library originally transcribed from Deepmind's tensorflow implementation, made conveniently into a

Phil Wang 665 Jan 08, 2023
TensorFlow Tutorials with YouTube Videos

TensorFlow Tutorials Original repository on GitHub Original author is Magnus Erik Hvass Pedersen Introduction These tutorials are intended for beginne

9.1k Jan 02, 2023
PyTorch package for the discrete VAE used for DALL·E.

Overview [Blog] [Paper] [Model Card] [Usage] This is the official PyTorch package for the discrete VAE used for DALL·E. Installation Before running th

OpenAI 9.5k Jan 05, 2023
Viewmaker Networks: Learning Views for Unsupervised Representation Learning

Viewmaker Networks: Learning Views for Unsupervised Representation Learning Alex Tamkin, Mike Wu, and Noah Goodman Paper link: https://arxiv.org/abs/2

Alex Tamkin 31 Dec 01, 2022
Vision Deep-Learning using Tensorflow, Keras.

Welcome! I am a computer vision deep learning developer working in Korea. This is my blog, and you can see everything I've studied here. https://www.n

kimminjun 6 Dec 14, 2022
Mix3D: Out-of-Context Data Augmentation for 3D Scenes (3DV 2021)

Mix3D: Out-of-Context Data Augmentation for 3D Scenes (3DV 2021) Alexey Nekrasov*, Jonas Schult*, Or Litany, Bastian Leibe, Francis Engelmann Mix3D is

Alexey Nekrasov 189 Dec 26, 2022
This is a Pytorch implementation of the paper: Self-Supervised Graph Transformer on Large-Scale Molecular Data.

This is a Pytorch implementation of the paper: Self-Supervised Graph Transformer on Large-Scale Molecular Data.

212 Dec 25, 2022
Efficient neural networks for analog audio effect modeling

micro-TCN Efficient neural networks for audio effect modeling

Christian Steinmetz 94 Dec 29, 2022
CONditionals for Ordinal Regression and classification in tensorflow

Condor Ordinal regression in Tensorflow Keras Tensorflow Keras implementation of CONDOR Ordinal Regression (aka ordinal classification) by Garrett Jen

9 Jul 31, 2022
Implementation of Kaneko et al.'s MaskCycleGAN-VC model for non-parallel voice conversion.

MaskCycleGAN-VC Unofficial PyTorch implementation of Kaneko et al.'s MaskCycleGAN-VC (2021) for non-parallel voice conversion. MaskCycleGAN-VC is the

86 Dec 25, 2022
MAVE: : A Product Dataset for Multi-source Attribute Value Extraction

MAVE: : A Product Dataset for Multi-source Attribute Value Extraction The dataset contains 3 million attribute-value annotations across 1257 unique ca

Google Research Datasets 89 Jan 08, 2023
MatryODShka: Real-time 6DoF Video View Synthesis using Multi-Sphere Images

Main repo for ECCV 2020 paper MatryODShka: Real-time 6DoF Video View Synthesis using Multi-Sphere Images. visual.cs.brown.edu/matryodshka

Brown University Visual Computing Group 75 Dec 13, 2022
Detail-Preserving Transformer for Light Field Image Super-Resolution

DPT Official Pytorch implementation of the paper "Detail-Preserving Transformer for Light Field Image Super-Resolution" accepted by AAAI 2022 . Update

50 Jan 01, 2023
🥇Samsung AI Challenge 2021 1등 솔루션입니다🥇

MoT - Molecular Transformer Large-scale Pretraining for Molecular Property Prediction Samsung AI Challenge for Scientific Discovery This repository is

Jungwoo Park 44 Dec 03, 2022
Deep generative modeling for time-stamped heterogeneous data, enabling high-fidelity models for a large variety of spatio-temporal domains.

Neural Spatio-Temporal Point Processes [arxiv] Ricky T. Q. Chen, Brandon Amos, Maximilian Nickel Abstract. We propose a new class of parameterizations

Facebook Research 75 Dec 19, 2022
Sign Language Translation with Transformers (COLING'2020, ECCV'20 SLRTP Workshop)

transformer-slt This repository gathers data and code supporting the experiments in the paper Better Sign Language Translation with STMC-Transformer.

Kayo Yin 107 Dec 27, 2022
CN24 is a complete semantic segmentation framework using fully convolutional networks

Build status: master (production branch): develop (development branch): Welcome to the CN24 GitHub repository! CN24 is a complete semantic segmentatio

Computer Vision Group Jena 123 Jul 14, 2022