From 9849cf446a210531755b7c265ebe4a4e9e22300b Mon Sep 17 00:00:00 2001 From: Natalia Shepeleva Date: Tue, 26 Feb 2019 15:57:05 +0100 Subject: [PATCH] First code commit --- README.md | 38 +- configs/config.py | 102 +++ configs/config_ConvNet.py | 63 ++ data_standardization/README.md | 20 + .../json/json_standardization.md | 113 ++++ .../txt/txt_standardization.md | 41 ++ main.py | 47 ++ network/InferenceRunner.py | 274 ++++++++ network/NetRunner.py | 354 +++++++++++ network/TrainRunner.py | 307 +++++++++ network/__init__.py | 15 + network/wrappers/ConvNet.py | 90 +++ network/wrappers/NetworkBase.py | 366 +++++++++++ network/wrappers/UNet.py | 129 ++++ network/wrappers/__init__.py | 15 + requirments.txt | 10 + utils/BatchIterator.py | 257 ++++++++ utils/DataParser.py | 588 ++++++++++++++++++ utils/__init__.py | 15 + utils/gradcam/GradCAM.py | 169 +++++ utils/gradcam/__init__.py | 0 utils/gradcam/readme.md | 19 + utils/utils.py | 111 ++++ 23 files changed, 3142 insertions(+), 1 deletion(-) create mode 100644 configs/config.py create mode 100644 configs/config_ConvNet.py create mode 100644 data_standardization/README.md create mode 100644 data_standardization/json/json_standardization.md create mode 100644 data_standardization/txt/txt_standardization.md create mode 100644 main.py create mode 100644 network/InferenceRunner.py create mode 100644 network/NetRunner.py create mode 100644 network/TrainRunner.py create mode 100644 network/__init__.py create mode 100644 network/wrappers/ConvNet.py create mode 100644 network/wrappers/NetworkBase.py create mode 100644 network/wrappers/UNet.py create mode 100644 network/wrappers/__init__.py create mode 100644 requirments.txt create mode 100644 utils/BatchIterator.py create mode 100644 utils/DataParser.py create mode 100644 utils/__init__.py create mode 100644 utils/gradcam/GradCAM.py create mode 100644 utils/gradcam/__init__.py create mode 100644 utils/gradcam/readme.md create mode 100644 utils/utils.py diff --git a/README.md b/README.md index e442c9e..930f475 100644 --- a/README.md +++ b/README.md @@ -1 +1,37 @@ -# training-engine \ No newline at end of file +# ALOHA Training Engine + +This is stand-alone Training Engine module ALOHA.eu project. http://aloha-h2020.eu + +## Setup +Training Engine was developed using Python 3.6, TensorFlow 1.12, PyTorch 1.0 and was tested under Windows 10 + +``pip install -r requirements.txt`` + +## Data Standardization +Data standardization description described in [data_standardization](data_standardization) + +## Architecture deployment +to be added + +## Training Configuration +to be added + + +## Supported Features +- [x] training/inference TensorFlow support +- [x] classification task support +- [x] segmentation task support + +## In development: +- [ ] training/inference PyTorch support +- [ ] detection task support +- [ ] tracking task support +- [ ] GAN architecture support +- [ ] hyperparameter optimization +- [ ] fast/full training mode +- [ ] accuracy prediction metric +- [ ] transfer leraning support + + +# Acknowledgements +This work was carried out by the European Union\`s Horizon H2020 Research and Innovation programme under grant agreement No. 780788 diff --git a/configs/config.py b/configs/config.py new file mode 100644 index 0000000..e5de37c --- /dev/null +++ b/configs/config.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# ----------------------------------------------------------------------------- +# Copyright (C) Software Competence Center Hagenberg GmbH (SCCH) +# All rights reserved. +# ----------------------------------------------------------------------------- +# This document contains proprietary information belonging to SCCH. +# Passing on and copying of this document, use and communication of its +# contents is not permitted without prior written authorization. +# ----------------------------------------------------------------------------- +# Created on : 11/16/2017 11:07 $ +# by : shepeleva $ +# SVN : $ +# + +# --- imports ----------------------------------------------------------------- + +import argparse + + +class ConfigFlags: + def __init__(self): + """ + + """ + parser = argparse.ArgumentParser(description='Tensorflow DL training pipeline') + # mandatory variables + parser.add_argument('--net', help='Network', + type=str, default='ConvNet') + parser.add_argument('--mode', help='training / test', + type=str, default='training') + parser.add_argument('--data_set', help='Name/ID of the used data set', + type=str, default='MNIST') + parser.add_argument('--data_dir', help='Learning data directory', + type=str, default='') + parser.add_argument('--data_file', help='Data file', + type=str) + parser.add_argument('--checkpoint_dir', help='Checkpoint directory', + type=str, default='ckpnt_dir') + parser.add_argument('--trainlog_dir', help='Train records directory', + type=str, default='tr_log') + parser.add_argument('--lr', help='Learning rate', + type=float, default=0.001) + parser.add_argument('--lr_decay', help='Learning rate decay rate', + type=float, default=0.0005) + parser.add_argument('--ref_steps', help='Refinement Steps', + type=int, default=5) + parser.add_argument('--ref_patience', help='Refinement Patience', + type=int, default=200) + parser.add_argument('--batch_size', help='Batch size', + type=int, default=32) + parser.add_argument('--num_epochs', help='Number of epochs', + type=int, default=100) + parser.add_argument('--loss', help='Loss function', + type=str, default='mse') + parser.add_argument('--optimizer', help='Optimizers: \n\t adam - adam optimizer ' + '\n\t gradient - gradient descent ' + '\n\t proximalgrad - proximal gradient descent ', + default='adam') + parser.add_argument('--dropout', help='Dropout Rate to use', + type=float, default=0.25) + parser.add_argument('--tb_record', help='Tensorboard records on/off', + type=bool, default=True) + parser.add_argument('--darkon_record', help='Darkon tool', + type=bool, default=False) + parser.add_argument('--gradcam_record', help='GradCam tool', + type=bool, default=False) + parser.add_argument('--gradcam_layers', help='Number of inspected convolution layers', + type=int, default=1) + parser.add_argument('--gradcam_layers_max', help='Number of convolution layers', + type=int, default=3) + parser.add_argument('--mi_record', help='MI tool', + type=bool, default=False) + parser.add_argument('--gpu_load', help='GPU load percentage [0.1 : 1]', + type=int, default=0.8) + # optional variables + parser.add_argument('--image_size', help='Image size', + type=list, default=[128, 128, 1]) + parser.add_argument('--num_classes', help='Number of labels', + type=int, default=2) + parser.add_argument('--num_filters', help='Number of filters', + type=int) + # todo actually implement following parameters in NetRunner + parser.add_argument('--filter_size', help='Filter size', + type=int) + parser.add_argument('--pool_size', help='Pool size', + type=int) + parser.add_argument('--stride_size', help='stride size', + type=int) + parser.add_argument('--nonlin', help='Nonlinearity', + type=str) + parser.add_argument('--upconv', help='Up convolution type: upconv or upsampling', + type=str) + parser.add_argument('--multi_task', help="multiple task, i.e. different loss functions", + type=bool) + self.args = parser.parse_args() + + def return_flags(self): + """ + + :return: + """ + return self.args diff --git a/configs/config_ConvNet.py b/configs/config_ConvNet.py new file mode 100644 index 0000000..a298b6c --- /dev/null +++ b/configs/config_ConvNet.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# ----------------------------------------------------------------------------- +# Copyright (C) Software Competence Center Hagenberg GmbH (SCCH) +# All rights reserved. +# ----------------------------------------------------------------------------- +# This document contains proprietary information belonging to SCCH. +# Passing on and copying of this document, use and communication of its +# contents is not permitted without prior written authorization. +# ----------------------------------------------------------------------------- +# Created on : 01/08/2018 16:29 $ +# by : shepeleva $ +# SVN : $ +# + +# --- imports ----------------------------------------------------------------- + +from configs.config import ConfigFlags + + +def load_config(): + config = ConfigFlags().return_flags() + + config.net = 'ConvNet' + config.training_mode = False + config.data_set = 'MNIST' + config.image_size = [28, 28, 1] + + config.lr = 0.001 + config.lr_decay = 0.1 + config.ref_steps = 10 + config.ref_patience = 1 + config.batch_size = 32 + config.num_epochs = 1000 + config.loss = 'mse' + config.optimizer = 'adam' + config.gradcam_record = True + config.gradcam_layers = 6 + config.gradcam_layers_max = 6 + config.mi_record = False + config.gpu_load = 0.8 + config.num_classes = 10 + config.class_labels = [i for i in range(9)] + config.num_filters = 16 + config.upconv = 'upconv' + config.nonlin = 'relu' + config.task_type = 'classification' + config.accuracy = 'mse' + config.augmentation = {'flip_hor': False, + 'flip_vert': False} + config.data_split = 0.7 + config.long_summary = True + config.trainable_layers = 'all' + config.normalize = True + config.zero_center = True + config.dropout = 0.4 + config.chpnt2load = '' + config.multi_task = False + config.cross_val = 1 + config.framework = 'tensorflow' + config.experiment_path = None + + + return config \ No newline at end of file diff --git a/data_standardization/README.md b/data_standardization/README.md new file mode 100644 index 0000000..e52af3c --- /dev/null +++ b/data_standardization/README.md @@ -0,0 +1,20 @@ +# data_standardization + +Description of custom dataset representation accepted by ALOHA tool + +Current support of data input into ALOHA tool is following: +- by picking `dataset` + >allowed entries: MNIST, CIFAR10, CIFAR100, + + if `` is picked, user have two options: + - from `data_file` + + > supported file formats: JSON, TXT + + - from `data_folder` + + > multiple file loading for classification and segmentation case + +For more detailed description check corresponding folder + +##### Important. Description provided in standardization files are not yet final. Changes my apply during development phase. diff --git a/data_standardization/json/json_standardization.md b/data_standardization/json/json_standardization.md new file mode 100644 index 0000000..e817fcc --- /dev/null +++ b/data_standardization/json/json_standardization.md @@ -0,0 +1,113 @@ +# JSON format standardization + +## General information +Rules on dataset description on JSON format. +This representation supports 3 task scenarios: +- Classification +- Segmentation +- Detection +- *In development: Traking, Multi-task* + +This standardization describes following input cases: +- IC1: single folder with images +- IC2: multiple folders with images +- IC3: single video +- IC4: multiple videos + +## Data loading to ALOHA toolflow +By using JSON format standardization, please, use parameter `data_file` in the configuration and pick JSON file, which describes your dataset. + +Please, be aware that all source locations in the JSON format standardization should contain ABSOLUTE path. + + +## Detailed standardization description +The standardization should be described as a dictionary of `: ` pairs. + +Allowed list of `key` values: + +- `name` - dataset name + >str value, describes dataset name, Ex.: 'random_set' +- `width` - width of the frame/image + >set value only if all frames/images of the same size, otherwise put 0 +- `height` - height of the frame/image + >set value only if all frames/images of the same size, otherwise put 0 +- `source` - source of the information (`video` or `image`) + >describes which source will be used, avaliable values: `video` or `image` +- `source_path` - absolute path to the source + >absolute or relative to the .json file path to the data source +- `mask_path` - absolute path to masks if presented + >absolute or relative to the .json file path to the masks (only for Segmentation task) +- `data_size` - number of frames per video / number of images in dataset + >depending on IC representaiton this value coud difer use following example:
+ for IC1 or IC3: 2340 - means that dataset represented by one folder with 2340 images in total OR by one video with 2340 frames in total
+ for IC2 or IC4: [345, 654, 123] - means that dataset represented by 3 folders with 345, 654 and 123 images accordingly OR by 3 videos with 345, 654 and 123 frames accordingly +- `meta`- detailed information for specific task + >in this section every frame/image should get detailed description accordingly to the task + +### `meta` for Classification +List of following dictionaries: +- `frame` - frame/image id + >for IC1: image_name
+ for IC2: [image_folder, image]
+ for IC3: frame_id
+ for IC4: [video_file_name, frame_id] +- `width` + >width of particular frame, if global width is not setted up +- `height` + >height of particular frame, if global height is not setted up +- `mask` - mask presence + >for this task should be equal to null +- `objects` - list of the descriptions of objects which should be classified in current frame + - `object_class` - object class indentification + >integer or one-hot labeling + - `bb` - bounding box + >for this task should be equal to null + - `polygon` - polygon area + >for this task should be equal to null + +### `meta` for Segmentation +List of following dictionaries: +- `frame` - frame/image id + >for IC1: image_name
+ for IC2: [image_folder, image]
+ for IC3: frame_id
+ for IC4: [video_file_name, frame_id] +- `width` + >width of particular frame, if global width is not setted up +- `height` + >height of particular frame, if global height is not setted up +- `mask`- mask presence, video/image representation might be independent from frame representaiton + >for IC1: image_name
+ for IC2: [image_folder, image]
+ for IC3: frame_id
+ for IC4: [video_file_name, frame_id] +- `objects` - list of the descriptions of objects which should be classified in current frame + - `object_class` - object class indentification + >integer or one-hot labeling + - `bb` - bounding box + >for this task should be equal to null + - `polygon` - polygon area + >list of points describing polygon + +### `meta` for Detection +List of following dictionaries: +- `frame` - frame/image id + >for IC1: image_name
+ for IC2: [image_folder, image]
+ for IC3: frame_id
+ for IC4: [video_file_name, frame_id] +- `width` + >width of particular frame, if global width is not setted up +- `height` + >height of particular frame, if global height is not setted up +- `mask` - mask presence + >for this task should be equal to null +- `objects` - list of the descriptions of objects which should be classified in current frame + - `object_class` - object class indentification + >integer or one-hot labeling + - `bb` - object boundaries + >should be described as [Xmin, Ymin, Xmax, Ymax], where
+ (Xmin, Ymin) pair specifying the lower-left corner
+ (Xmax, Ymax) pair specifying the upper-right corner + - `polygon` - polygon area + >list of points describing polygon diff --git a/data_standardization/txt/txt_standardization.md b/data_standardization/txt/txt_standardization.md new file mode 100644 index 0000000..3c1dc51 --- /dev/null +++ b/data_standardization/txt/txt_standardization.md @@ -0,0 +1,41 @@ +# TXT format standardization + +## General information +Rules on dataset description on TXT format. +This representation supports 2 task scenarios: +- Classification +- Segmentation +- Detection +- *In development: Traking, Multi-task* + +This standardization describes following input cases: +- IC1: single TXT file + +## Data loading to ALOHA toolflow +- IC1 case: please, use parameter `data_file` in the configuration and pick TXT file, which describes your dataset. + +Please, be aware that all source locations in the TXT format standardization should contain ABSOLUTE path. + +## Detailed standardization description +The standardization should be described as a list of paticular fileds separated by space depending on the task. + +### Classification +File structure: `