Ava ML is a toolkit that simplifies supervised training of neural networks for research purposes. It is designed facilitate many tasks common in applying deep neural networks.
Features of Ava ML include:
Standard models, datasets and metrics: Avoids re-implementations and allows for a quick start. Datasets can be downloaded with a single command and shared with other users on the same system.
Feature Extractors: A large number implemented feature extractors pre-trained on ImageNet
(via the pretrainedmodels
python package)
Command Line Interface: Train and evaluate models by running simple instructions in the command line.
Experiment definitions: Facilitates reproducibility and describes hyperparameters in a transparent way. Direct output of latex tables is possible.
Visual inspection of datasets: Enables verification that datasets (including their parameters) are properly implemented.
Standard Structure: The division into models, datasets and metrics facilitates collaboration in projects when multiple persons are involved.
Note, this is an early preview version not meant to be used in production.
To install ava, first clone the git repository using
git clone https://gitlab.gwdg.de/cns-group-public/ava-ml
Now the package can be installed by:
python3 setup.py develop --user
The setup will create a folder ~/.ava
containing the file paths.yaml
.
TRAINED_MODELS_PATH
location where trained models are stored.
To prevent overwriting important models consider changing the access rights chmod a-w <model-file>
.CACHE_PATH
location where data is cached (sometimes required for fast training)DATASETS
location of datasetsAlso the path to every individual dataset can be set. E.g. by adding a line:
MNIST: /path/to/mnist
Here are a few ideas of what to do next:
./build-doc.py
and open doc/index.htm
in a browser.tests
.ava train <model> <dataset>
.We differentiate two phases: training and scoring (or evaluation). Training will result in a model and a model-args file being created that encode the obtained parameters (weights).
Models are trained and evaluated on datasets using a metric. All three components are defined separately and can be exchanged almost freely (given they are compatible). This means that once an image classification model is designed, it can be trained on all image classification datasets.
These are re-usable components of the model.
Common operations such as image resizing.
Use ava inspect <dataset> <dataset-args>
to explore datasets.
Training and evaluation are expensive. Hence, many intermediate results are cached.
__init__()
: Initialization of the model (e.g. initialize the neural network)forward(*x)
: Receive inputs *x
and do forward passBaselines are special models that are not trained but have direct access to the Dataset.
They are indicated by returning True
in the method is_baseline
. Using the access to the
dataset, e.g. the mode of the label distribution can be computed.
Blocks are re-useable components of neural networks.
The feature extraction API provides access several state-of-the-art feature extractors.
For example, these can be combined with an image classifier
(see ImageClassifier
for details) or initialized in custom code using
from ava.models.feature_extraction import get_feature_extractor fe = get_feature_extractor('resnet50')
.dilated_resnet: drn38, drn54, drn105
.inception: bninception, xception, inception4, inception3
.lightweight: mnist_net, light_unet, light_convnet
.resnet: resnet18, resnet50, resnet101, resnet152
.se_resnet: se_resnet50, se_resnet101, se_resnext50, se_resnext101
.squeezenet: squeezenet
.yolo: yolo, yolo_openimages
The loss function tells us how good the predictions of the model match the ground truth provided by the dataset. Several loss functions have been implemented.
Custom implementations for several dataset are provided. A list can be found below.
The data type describes the input and ground truth of the dataset.
For image classification this would be image(input_image)->C(class)
.
Names can be optionally provided in brackets.
super().__init__('image(input_image)->C(class)')
C
: categoricalM
: multi-labeldenseC
: pixel-wise categoricaldenseM
: pixel-wise multi-labelimage
: RGB imagevideo
: RGB videovideoGS
: greyscale video__init__(subset, seed)
: Initialization of the datasetsubset
: Defines the subset.seed
: Can be used to randomly generate different subsets. Useful for cross-validation.__getitem__(idx)
:idx
: index into the samples array, i.e. draws the idx
-th sample.sample_ids
: List of sample identifiers. Its length determines the dataset length.
This attribute should be set in the __init__
method.default_loss
: Default loss function to be used.default_metrics
: List of default metrics.model_config
: Arguments to be passed to the model. E.g. number of classesvisualization_hooks
: Dictionary of functions to apply on input and outputs.
E.g. convert classification id back to name.additional_visualizations
: Additional visualizations, combining different inputs and outputs.Here some common data transformations are defined that can be used to build a Dataset object.
Components of ava can be called within python scripts.
To load a pre-trained model:
from ava.models import load_pretrained_model model = load_pretrained_model('model_name')
It is also straightforward to use transformations:
from ava.transformations import tensor_resize, random_crop img = tensor_resize(img, (100, 100), interpret_as_min_bound=True) img = random_crop(img, (100, 100))
The command line interface of ava offers several options:
ava train <model> <dataset> <options>
ava score <model> <dataset> <options>
ava inspect <dataset>
check the dataset implementionava benchmark <dataset>
assess the speed and potential bottlenecks in datasetsava experiment <experiment-definition>
run experimentYou can define customized datasets outside the ava source code tree by defining
datasets or models in python modules ending with _dataset.py
or _model.py
in your
project folder. When these are available the defined datasets and models are
available to be used in the CLI or experiment files.
See the examples/sample_project
folder for an example.
Experiments can be defined in yaml by specifying a pairs of models
and datasets as well as their parameters. You can find examples of experiment definitions ins the experiments
folder,
e.g. run
ava experiment experiments/mnist.yaml
Important variables are:
common_train_args
: arguments that hold for all model-dataset pairs for training (e.g. batch size)common_test_args
: arguments that hold for all model-dataset pairs for evaluationconfigurations
: A list of individual (model, dataset, parameter) tuples for training.test_dataset
: A list of datasets (with parameters) for evaluation.individual_test_dataset
: A list of individual evaluation datasets (with parameters) for each configuration.The experiment can generate tables which can be directly used in tex files. These are the relevant parameters:
tex_transpose
for more parameters see the example experiment files
There are some useful preparation tools available using
ava tool <tool>
Here <tool>
can be one of these:
rescale
Rescale Imagesextract-features
extract features from imagesextract-frames
extract frames from videoslist-files
writes an index of text filesvalidate-dataset
check if subsets overlapclean-models
remove modelsdownload-video
downloads videoThis folder and its subfolder contain modules that are relevant for the core functions of the library, e.g. training and scoring models.
Ava is strcutured into several sub-packages.
core
(see below)datasets
: Dataset defintionsmetrics
: Metrics to measure performancemodels
(see below)scripts
: Useful toolsthird_party
: Code that was not written by ustransformations
: Data preprocessing routinesThis sub-package contains core functions such as for launching training and experiments. It involves the following subpackages:
common
: data_types
: Definitions of data types for visualizationtraining
: Training logicvisualize
: Framework for visualizing input data and predictionsAdditionally these modules exist:
arguments
: The argparse
configuration for the CLIbenchmarks
: dataset
: experiment
: model
:plots
:logging
: Logging to console, log file and visdomscore
:table
:visualize
:The models directory contains implementations of several models.
video:
Models for video classification.dense:
Models that predict densely, e.g. for semantic segmentation.deprecated:
Old models that should no longer be used. These models will not be available on the CLI.