Giter Club home page Giter Club logo

pytorch-netvlad's Introduction

pytorch-NetVlad

Implementation of NetVlad in PyTorch, including code for training the model on the Pittsburgh dataset.

Reproducing the paper

Below are the result as compared to the results in third row in the right column of Table 1:

R@1 R@5 R@10
NetVlad paper 84.1 94.6 95.5
pytorch-NetVlad(alexnet) 68.6 84.6 89.3
pytorch-NetVlad(vgg16) 85.2 94.8 97.0

Running main.py with train mode and default settings should give similar scores to the ones shown above. Additionally, the model state for the above run is available here: https://drive.google.com/open?id=17luTjZFCX639guSVy00OUtzfTQo4AMF2

Using this checkpoint and the following command you can obtain the results shown above:

python main.py --mode=test --split=val --resume=vgg16_netvlad_checkpoint/

Setup

Dependencies

  1. PyTorch (at least v0.4.0)
  2. Faiss
  3. scipy
  4. tensorboardX

Data

Running this code requires a copy of the Pittsburgh 250k (available here), and the dataset specifications for the Pittsburgh dataset (available here). pittsburgh.py contains a hardcoded path to a directory, where the code expects directories 000 to 010 with the various Pittsburth database images, a directory queries_real with subdirectories 000 to 010 with the query images, and a directory datasets with the dataset specifications (.mat files).

Usage

main.py contains the majority of the code, and has three different modes (train, test, cluster) which we'll discuss in mode detail below.

Train

In order to initialise the NetVlad layer it is necessary to first run main.py with the correct settings and --mode=cluster. After which a model can be trained using (the following default flags):

python main.py --mode=train --arch=vgg16 --pooling=netvlad --num_clusters=64

The commandline args, the tensorboard data, and the model state will all be saved to opt.runsPath, which subsequently can be used for testing, or to resuming training.

For more information on all commandline arguments run:

python main.py --help

Test

To test a previously trained model on the Pittsburgh 30k testset (replace directory with correct dir for your case):

python main.py --mode=test --resume=runsPath/Nov19_12-00-00_vgg16_netvlad --split=test

The commandline arguments for training were saved, so we shouldnt need to specify them for testing. Additionally, to obtain the 'off the shelf' performance we can also omit the resume directory:

python main.py --mode=test

Cluster

In order to initialise the NetVlad layer we need to first sample from the data and obtain opt.num_clusters centroids. This step is necessary for each configuration of the network and for each dataset. To cluster simply run

python main.py --mode=cluster --arch=vgg16 --pooling=netvlad --num_clusters=64

with the correct values for any additional commandline arguments.

pytorch-netvlad's People

Contributors

nanne avatar saibr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.