NLE practical session for PAISS 2018
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
data reorganize with models dict Jun 30, 2018
datasets add input image option Jul 1, 2018
utils change print Jul 1, 2018
.gitignore Initial commit Jun 25, 2018
LICENSE Initial commit Jun 25, 2018 update readme Jul 3, 2018 fix typo Jun 30, 2018 bug fix Jul 4, 2018 fixed ap for PQ Jun 30, 2018 first commit Jun 25, 2018 add ex Jul 2, 2018


NLE practical session for PAISS 2018


This code requires Python 3 and Pytorch 0.4. Follow the instructions below to install all the necessary dependencies.

Linux / MacOS

First, download and install the appropriate version of miniconda following the instructions for MacOS or Linux.

Then run the following commands:

source $HOME/miniconda3/bin/activate #Activates your conda environment
conda install numpy matplotlib ipython scikit-learn
conda install pytorch torchvision faiss-cpu -c pytorch

On MacOS there’s a bug for faiss related to libomp ( run “brew install libomp” (see to install brew) to resolve this bug.


Install anaconda on windows (launch .exe file downloaded from the conda website). It has to be python 3 (pytorch doesn’t support 2.7 on windows)

In the anaconda prompt, run:

conda create -n pytorch
activate pytorch
conda install pytorch-cpu -c pytorch
pip install torchvision --no-deps
conda install pillow

NOTE: The FAISS package is not supported on Windows. Participants with Windows machines must follow the product quantization exercise with their neighbours.

Downloading the code, dataset, and models

First, clone this repository:

cd $HOME/my_projects
git clone

Then, you will need to download 4 files:

  • oxbuild_images.tgz (1.8GB)
  • gt_files_170407.tgz (280KB)
  • features.tgz (579MB)
  • models.tgz (328MB)

and store them in the appropriate paths.

Note: All paths in this section are relative to the root directory of this repository.

Oxford dataset

On Linux/MacOS, execute the following:

cd $HOME/my_projects/paiss
wget -O images.tgz
mkdir -p data/oxford5k/jpg && tar -xzf images.tgz -C data/oxford5k/jpg
wget -O gt_files.tgz
mkdir -p data/oxford5k/lab && tar -xzf gt_files.tgz -C data/oxford5k/lab

On Windows, perform the following:

Features and models

On Linux/MacOS, execute the following:

cd $HOME/my_projects/paiss
wget -O features.tgz
tar -xzf features.tgz -C data
wget -O models.tgz
tar -xzf models.tgz -C data

On Windows, perform the following:



source $HOME/miniconda3/bin/activate
cd $HOME/my_projects/paiss
python --qidx 42 --topk 5

and you should see the following ouput:

Output Demo


To go through the practical session, we will use the script. This scrip contains all the exercises and questions in the comments, and accepts the following arguments:

  • --sect [str]: Selects the section of the session to be run. You can select one section between 1a to 1i, and 2a to 2g.
  • --qidx [int]: Selects the query index that you want to use for the section. Each section has already some default indexes, so this argument is not strictly required.
  • --hide-tsne: This flag desactivate the tsne computation. In some sections you may want to experiment with different queries and not to visualize the TSNE projection again (since this may take between 30 seconds to several minutes depending on your CPU :S)

We recommend running the session from iPython using the command %run, since this allows you to visualize the variables that were created during the execution (eg. you may want to check a given layer of the network). Here's an example:

source $HOME/miniconda3/bin/activate
cd $HOME/my_projects/paiss
> %run --sect 1i --hide-tsne --qidx 23
> qfeats.shape
> qfeats[q_idx]

Which will show the following results:

Output Terminal

Output Session

Note: If you don't have iPython installed, you can install it using the following conda command: conda install ipython

Note: The code is automatically saving the plots generated in the folder results/

Link to the slides: PDF 30MB