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.
For simplicity, I commited results from five runs in this repo.
pip install git+https://github.com/velikodniy/tbparser.git
Evaluation.ipynb to compare the runs.
- 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.
- Download the small dataset from kaggle to
- Download the full dataset from kaggle to
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
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 --help to learn what other parameters you can provide.
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
I want to use larger images during training
No problem, simple change
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:
- Manually copy the outputs of previous command to