Skip to content

A collection of scripts for training, testing, and applying CNNs using Keras.

Notifications You must be signed in to change notification settings

cpra/keras-scripts

Repository files navigation

Keras Scripts

A collection of scripts based on Keras that I use for training, testing, and applying CNNs.
Supports Python 3.5 and Keras 0.3 (other versions might work too).

Scripts

The repository currently contains the following scripts. More to follow.

train.py

train.py is used for training (or fine-tuning) Keras CNNs. The script works in conjunction with a JSON file that encodes general properties that usually do not change often, such as the net and data to use. See train.example.json for an example. The network structure itself is expected to be returned by a Python function, see train.example.json and kutils/netdefs.py for examples.

The script saves model weights in the form MODEL_ep3.h5, where ep3 means "after third training epoch". For each weights file there is a corresponding info file, e.g. MODEL_ep3.h5.info that stores everything needed to use the trained model, including network structure and preprocessing information. Furthermore, the script will create a log file (by default MODEL.log) that contains information on the training progress.

train.py expects the training data to be stored in one or several HDF5 files, and these files must have two datasets, X (a samples * channels * rows * columns numpy array of feature vectors) and y (a samples, numpy array of class labels). See train.example.json.


visualize_log.py

visualize_log.py can be used to visualize logs generated by train.py in order to get a better idea of how training progressed (or progresses, the script supports logs that are being written).


stack_logs.py

Stacks multiple training logs together to form a new log. Useful to join logs generated by continuing training multiple times.


visualize_samples.py

visualize_samples.py can be used to visualize data samples, in raw form or including minibatch augmentation (see --augmnent).


visualize_weights.py

visualize_weights.py can be used to visualize weights of convolutional layers.


test.py

test.py is used for testing a model trained using train.py on test data in the form of a single HDF5 file (see notes on train.py for details). The scripts uses a .info file to figure out which model, weights, and preprocessing to use.


average_predictions.py

This script can be used to average multiple predictions (written to files using test.py) to assess the performance of a network ensemble.


apply_to_image.py

apply_to_image.py applies a model trained using train.py on on an image by sampling patches in a sliding window fashion. The predicted probabilities are then visualized as a color image (one channel per class, supports max. 3 classes).


lrdecay.py

lrdecay.py visualizes how learning rate decay will influence the learning rate over time.

Author

Christopher Pramerdorfer
CVL, TU Wien, Vienna, Austria

License

zlib

About

A collection of scripts for training, testing, and applying CNNs using Keras.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages