Team o_O solution for the Kaggle Diabetic Retinopathy Detection Challenge
Extract train/test images to
data/trainand
data/testrespectively and put the
trainLabels.csvfile into the
datadirectory as well.
Install python2 dependencies via,
pip install -r requirements.txtYou 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
deterministicbranch. Note that the branch has its own
requirements.txtfile. 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.
A commented bash script to generate our final 2nd place solution can be found in
make_kaggle_solution.sh.
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
--helpto display a brief help message. They are meant to be executed in the order,
convert.pycrops and resizes images
train_nn.pytrains convolutional networks
transform.pyextracts features from trained convolutional networks
blend.pyblends 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. ```
configsdirectory.
blend.yml.
blend.pydirectly.
data/test_mediumdirectory
test_dirfield in your config file(s) inside the
configsdirectory
--test_dir /path/to/test/filesargument to
transform.pyand
blend.py