kXborg d1f4c853f4 Added download button 2 år sedan
..
README.md d1f4c853f4 Added download button 2 år sedan
animals_dataset.py 6c8a5f9507 add t-sne visualization (#3) 4 år sedan
requirements.txt ec9c13eb87 Add requirements 4 år sedan
resnet.py 6c8a5f9507 add t-sne visualization (#3) 4 år sedan
tsne.py 8e9972ae7b Use matplotlib for all visualizations. With opencv at one place and matplotlib at another one it was very confusing for user. The issue was with vis closing - for matplotlib one shold close the window, while for opencv it should press any key. Otherwise, if one closes the opencv window, the script will run forever 4 år sedan

README.md

t-SNE for Feature Visualization

This repository contains code for t-SNE for Feature Visualization blog post.

download

Setup

This code was tested with python 3.7, however, it should work with any python 3.

  1. Create and activate virtual environment for experiments with t-SNE.
python3 -m venv venv
source venv/bin/activate
  1. install the dependencies
python3 -m pip install -r requirements.txt

Data downloading

Download data from Kaggle and unzip it. The easiest way is to use kaggle console API. To setup it, follow this guide. However, you can download the data using your browser - results will be the same.

After that, execute the following commands:


kaggle datasets download alessiocorrado99/animals10

mkdir -p data

cd data

unzip ../animals10.zip

cd ..

Executing the T-SNE visualization


python3 tsne.py

Additional options:

python3 tsne.py -h

usage: tsne.py [-h] [--path PATH] [--batch BATCH] [--num_images NUM_IMAGES]

optional arguments:
  -h, --help            show this help message and exit
  --path PATH
  --batch BATCH
  --num_images NUM_IMAGES

You can change the data directory with --path argument.

Tweak the --num_images to speed-up the process - by default it is 500, you can make it smaller.

Tweak the --batch to better utilize your PC's resources. The script uses GPU automatically if it available. You may want to increase the batch size to utilize the GPU better or decrease it if the default batch size does not fit your GPU.