Patch-NetVLAD: An open-source Python implementation of the CVPR2021 paper
Project description
Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition
This repository contains code for the CVPR2021 paper "Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition"
A pre-print version of the article can be found at: https://arxiv.org/abs/2103.01486
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={},
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 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 ifground_truth_path
is specified)NetVLAD_predictions.txt
with top 100 reference images for each query images obtained using "vanilla" NetVLAD in Kapture formatPatchNetVLAD_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 configs/performance.ini \
--first_im_path=example_images/tokyo_query.jpg \
--second_im_path=example_images/tokyo_db_patch_success.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
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:
- 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.
- Select your own choice of posDistThr value.
- 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file patchnetvlad-0.1.4.tar.gz
.
File metadata
- Download URL: patchnetvlad-0.1.4.tar.gz
- Upload date:
- Size: 6.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0a6dc49bdf613893e82b50864c5cbaab5b6836ed0bb4534a1a531bfd62c7b73 |
|
MD5 | bcd781a3c1cbfa280e9beead49ace493 |
|
BLAKE2b-256 | 7e4d8c152aa1013099a9cac629506b7cafc12956789b2e5058de49cf66525f57 |
File details
Details for the file patchnetvlad-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: patchnetvlad-0.1.4-py3-none-any.whl
- Upload date:
- Size: 6.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88597f72860ff41494ebe04570811bd7e630838e67361e521e383594f80f1016 |
|
MD5 | b0c693d379fbabdcbd9b59fbaf6b2502 |
|
BLAKE2b-256 | 34c07005c4912340d8b01d67573b5d7efc1e0b30da2b7e3dde06e92d3a84dc37 |