Skip to content
Implementation of prototypical networks
Jupyter Notebook Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
prototypical_networks
results
.gitignore
Data exploration.ipynb
Evaluation.ipynb
LICENSE
README.md
calculate_dataset_statistics.py
config.py.sample
experiments.txt
main.py
requirements.txt
utils.py

README.md

Prototypical networks for few-shot learning

This repository contains an implementation of the paper "Prototypical Networks for Few-shot Learning". The code is heavily based on / in part copies from https://github.com/oscarknagg/few-shot/. All copied parts are clearly marked.

Dataset used is the Fashion Product Images dataset from Kaggle.

Results

For simplicity, I commited results from five runs in this repo.

Run pip install git+https://github.com/velikodniy/tbparser.git

Then see Evaluation.ipynb to compare the runs.

Getting started

Requirements

  • python>=3.6
  • pip install -r requirements.txt
  • for image resizing (see "Getting the data") you need ImageMagick installed

Getting the data

The data exploration notebook uses the small as well as the full dataset. For everything else, only the full dataset is needed; i.e. skip downloading the small dataset if you are not interested in the data exploration notebook.

  1. mkdir data
  2. Download the small dataset from kaggle to data.
  3. Download the full dataset from kaggle to data.
cd data
unzip fashion-product-images-small.zip -d small
unzip fashion-product-images-dataset.zip -d full

# decrease image size in the full dataset
cd full
cp -r full/images full/images_225x300     # this step might take a while
mogrify -resize 225x300 *.jpg             # this will take even longer

Configuration

cp config.py.sample config.py

Per default, the config assumes data to be located in the directories used in "Getting the data". If you used different directories -> change the config. If you do not have a GPU -> change the config.

Running an experiment

Very short experiment to check that everything works

python main.py --num-episodes=10 --num_epochs=10

Experiment with default settings

python main.py

Check out python main.py --help to learn what other parameters you can provide.

Details

Image size

The images in the full dataset are fairly large (1800x2400 pixels). Due to GPU limitations (and general dataset limitations, as mentioned in Evaluation.ipynb), I decided to decreased them in size.

To make image loading faster, I decreased the files themselves to 225x300 pixels. During image loading, they are further decreased to 112x150 pixels (solely due to GPU limitations this time).

I want to use larger image files

No problem, just adapt the IMAGE_FOLDER variable config.py

I want to use larger images during training

No problem, simple change IMAGE_SIZE in config.py. You might have to re-calculate the image means and standard deviations (but to be honest, they don't differ all that much when resizing the image). But, anyway, here is how to do that:

  1. Change IMAGE_SIZE in config.py
  2. python calculate_dataset_statistics.py
  3. Manually copy the outputs of previous command to IMAGE_STATISTICS in config.py
You can’t perform that action at this time.