by sveitser

Team o_O solution for the Kaggle Diabetic Retinopathy Detection Challenge

212 Stars 116 Forks Last release: Not found MIT License 174 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Kaggle Diabetic Retinopathy Detection


Extract train/test images to

respectively and put the
file into the
directory as well.

Install python2 dependencies via,

pip install -r requirements.txt
You need a CUDA capable GPU with at least 4GB of video memory and CUDNN installed.

If you'd like to run a deterministic variant you can use the

branch. Note that the branch has its own
file. In order to achieve determinism cuda-convnet is used for convolutions instead of cuDNN. The deterministic version increases the GPU memory requirements to 6GB and takes about twice as long to run.

The project was developed and tested on arch linux and hardware with a i7-2600k CPU, GTX 970 and 980Ti GPUs and 32 GB RAM. You probably need at least 8GB of RAM as well as up to 160 GB of harddisk space (for converted images, network parameters and extracted features) to run all the code in this repository.


Generating the kaggle solution

A commented bash script to generate our final 2nd place solution can be found in


Running all the commands sequentially will probably take 7 - 10 days on recent consumer grade hardware. If you have multiple GPUs you can speed things up by doing training and feature extraction for the two networks in parallel. However, due to the computationally heavy data augmentation it may be far less than twice as fast especially when working with 512x512 pixel input images.

You can also obtain a quadratic weighted kappa score of 0.839 on the private leaderboard by just training the 4x4 kernel networks and by performing only 20 feature extraction iterations with the weights that gave you the best MSE validation scores during training. The entire ensemble only achieves a slightly higher score of 0.845.


All these python scripts can be invoked with

to display a brief help message. They are meant to be executed in the order,
  • convert.py
    crops and resizes images
  • train_nn.py
    trains convolutional networks
  • transform.py
    extracts features from trained convolutional networks
  • blend.py
    blends features, optionally blending inputs from both patient eyes

Example usage:

python convert.py --crop_size 128 --convert_directory data/train_tiny --extension tiff --directory data/train
python convert.py --crop_size 128 --convert_directory data/test_tiny --extension tiff --directory data/test
``` Usage: convert.py [OPTIONS]

Options: --directory TEXT Directory with original images. [default: data/train] --convertdirectory TEXT Where to save converted images. [default: data/trainres] --test Convert images one by one and examine them on screen. [default: False] --crop_size INTEGER Size of converted images. [default: 256] --extension TEXT Filetype of converted images. [default: tiff] --help Show this message and exit ```


Example usage:

python train_nn.py --cnf configs/c_128_5x5_32.py
python train_nn.py --cnf configs/c_512_5x5_32.py --weights_from weigts/c_256_5x5_32/weights_final.pkl
``` Usage: train_nn.py [OPTIONS]

Options: --cnf TEXT Path or name of configuration module. [default: configs/c5124x4tiny.py] --weightsfrom TEXT Path to initial weights file. --help Show this message and exit. ```


Example usage:

python transform.py --cnf config/c_128_5x5_32.py --train --test --n_iter 5
python transform.py --cnf config/c_128_5x5_32.py --n_iter 5 --test_dir path/to/other/image/files
python transform.py --test_dir path/to/alternative/test/files
``` Usage: transform.py [OPTIONS]

Options: --cnf TEXT Path or name of configuration module. [default: configs/c5124x432.py] --niter INTEGER Iterations for test time averaging. [default: 1] --skip INTEGER Number of test time averaging iterations to skip. [default: 0] --test Extract features for test set. Ignored if --testdir is specified. [default: False] --train Extract features for training set. [default: False] --weightsfrom TEXT Path to weights file. --test_dir TEXT Override directory with test set images. --help Show this message and exit. ```


Example usage: ``` python blend.py --perpatient # use configuration in blend.yml python blend.py --perpatient --featurefile path/to/feature/file python blend.py --perpatient --test_dir path/to/alternative/test/files

Usage: blend.py [OPTIONS]

Options: --cnf TEXT Path or name of configuration module. [default: configs/c5124x432.py] --predict Make predictions on test set features after training. [default: False] --perpatient Blend features of both patient eyes. [default: False] --featuresfile TEXT Read features from specified file. --niter INTEGER Number of times to fit and average. [default: 1] --blendcnf TEXT Blending configuration file. [default: blend.yml] --testdir TEXT Override directory with test set images. --help Show this message and exit. ```


  • The convolutional network configuration is done via the files in the
  • To select different combinations of extracted features for blending edit
  • To tune parameters related to blending edit
  • To make predictions for a different test set either
    • put the resized images into the
    • or edit the
      field in your config file(s) inside the
    • or pass the
      --test_dir /path/to/test/files
      argument to

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.