Home

Awesome

This repository contains a generator for Keras (using a channel last configuration, eg with TensorFlow backend), capable of handling 2D and 3D arrays, and augmenting the data using affine transforms and elastics deformations while being based on keras.utils.Sequence for efficient and safe multiprocessing.

The requirements for the generator and augmentation are the following: numpy, matplotlib, scipy, and keras (only for the generator part)

The demo requires on top: SimpleITK and pydicom

Multiprocessing

In order to use mulitprocessing, you need to specify it in your call to fit_generator:

model.fit_generator(generator=generator,
                    use_multiprocessing=True,
                    workers=8)
                    

use_multiprocessing should be True, otherwise it defaults to False and you'll be using only one thread. The number of workers (ie thread) is also to be choosen (1 is the default value), if you have no idea pick something between your CPU core count and thread count.

Files

the params dictionnary

is used to supply the generator with a lot of useful informations regarding the data to be generated. The following list explains the parameters useful for data generation:

the augmentation techniques

The file contains 2 augmentation "techniques": - elastic deformation with 2 different methods: deform_pixel on a pixel wide basis and deform_grid on a grid basis. - random_transform, which provides most of the keras image augmentation techniques.

These 3 functions take as input X (the image), Y (an optionnal mask), and some keyed parameters. They also work both on 2D and 3D images. They depend on numpy and scipy.ndimage Elastic deformation is quite slow for 3D images, one could try to tune the order of the splines used for the different interpolations.

random_transform

The following parameters can be supplied in the random_transform dictionnary:

e_deform

for grid based deformation, name the dictionnary "e_deform_g":

for pixel based deformation, name the dictionnary "e_deform_p":

save_image

The function save_image can be used to save the predicted images, see the save_predict function in demo.py

Demo images

A few examples are present in the demo folder extracted from the 3D-IRCADb 01 dataset (https://www.ircad.fr/research/3d-ircadb-01/)

One with deform_grid

'augmentation': [1, 0, 1], 'random_deform': {'rotation_range_alpha': 20, 'width_shift_range': 0.1, 'height_shift_range': 0.1}, 'e_deform': {'points': 3, 'sigma': 10}

CT scans masks of the scans

One with deform_pixel

'augmentation': [1, 1, 0], 'random_deform': {'height_shift_range': 0.1, 'width_shift_range': 0.1, 'rotation_range_alpha': 20}, 'e_deform': {'sigma': 3, 'alpha': 10} 

CT scans masks of the scans