Ejemplo n.º 1
0
def test_run_experiment():
    exp = Experiment(
        log_base_path='../../oxford_perf/logs',
        best_model_monitors=['val_loss', 'val_accuracy']).from_full_config(
            'tests/json/sample_dataset_xs_config.json').run_experiment(
                train_history_log=True,
                model_checkpoint_period=1,
                prediction_checkpoint_period=1,
                epochs=2).plot_performance().plot_prediction(
                    masked_images=[i for i in range(10)], ).plot_prediction(
                        [i for i in range(10)],
                        img_name='Prediction_{index:02d}_contour.png',
                        contour=True).plot_prediction(
                            [i for i in range(10)],
                            img_name='Prediction_{index:02d}.png',
                            contour=False)

    # Best model in this run
    print(exp.best_model())
Ejemplo n.º 2
0
def test_continue_experiment():
    exp = Experiment(
        log_base_path='../../oxford_perf/logs',
        best_model_monitors=[
            'val_loss', 'val_accuracy'
        ]).from_file('tests/h5_files/model.002.h5').run_experiment(
            train_history_log=True,
            model_checkpoint_period=1,
            prediction_checkpoint_period=1,
            epochs=3,
            initial_epoch=2).plot_performance().plot_prediction(
                masked_images=[i for i in range(10)], )
Ejemplo n.º 3
0
def test_run_experiment_different_size():
    exp = Experiment(
        log_base_path='../../oxford_perf_2/logs',
        best_model_monitors=['val_loss', 'val_accuracy']).from_full_config(
            'tests/json/sample_dataset_xs_config_diff_size.json'
        ).run_experiment(train_history_log=True,
                         model_checkpoint_period=1,
                         prediction_checkpoint_period=1,
                         epochs=2).plot_performance().plot_prediction(
                             masked_images=[i for i in range(10)],
                             base_image_name='00/x',
                             truth_image_name='00/y',
                             predicted_image_name='00/predicted')

    # Best model in this run
    print(exp.best_model())

    exp.run_test(masked_images=[i for i in range(10)],
                 base_image_name='00/x',
                 truth_image_name='00/y',
                 predicted_image_name='00/predicted')
Ejemplo n.º 4
0
from deoxys.experiment import Experiment

exp = Experiment(
    log_base_path='../../hn_perf/test'
).from_file('../../hn_perf/logs_saved/model.003.edited.h5').run_test(
    masked_images=[i for i in range(42)]).run_test(
        masked_images=[i for i in range(198)],
        use_original_image=True,
        image_name='Patient{patient_idx:03d}_Slice{slice_idx:03d}',
        image_title_name='Patient {patient_idx:03d}, Slice {slice_idx:03d}')
Ejemplo n.º 5
0
if __name__ == '__main__':
    if not tf.test.is_gpu_available():
        raise RuntimeError("GPU Unavailable")

    parser = argparse.ArgumentParser()
    parser.add_argument("config_file")
    parser.add_argument("log_folder")
    parser.add_argument("--epochs", default=500, type=int)
    parser.add_argument("--model_checkpoint_period", default=25, type=int)
    parser.add_argument("--prediction_checkpoint_period", default=25, type=int)

    args = parser.parse_args()

    # 42 images for 2d, 15 images for 3d
    img_num = 100

    if '3d' in args.log_folder:
        img_num = 40

    # config = read_file(args.config_file)
    if os.path.isfile(args.config_file) and args.config_file.endswith('h5'):
        initial_epoch = int(args.config_file[-6:-3])
    else:
        raise RuntimeError('Not a model file')
    (
        Experiment(log_base_path=args.log_folder)
        .from_file(args.config_file)
        .run_test(masked_images=[i for i in range(img_num)])
    )
Ejemplo n.º 6
0
    parser.add_argument("log_folder")
    parser.add_argument("--epochs", default=500, type=int)
    parser.add_argument("--model_checkpoint_period", default=25, type=int)
    parser.add_argument("--prediction_checkpoint_period", default=25, type=int)

    args = parser.parse_args()

    # strategy = tf.distribute.MirroredStrategy()
    # print('Number of devices: {}'.format(strategy.num_replicas_in_sync))

    # with strategy.scope():
    config = read_file(args.config_file)

    exp = Experiment(
        log_base_path=args.log_folder).from_full_config(config).run_experiment(
            train_history_log=True,
            model_checkpoint_period=args.model_checkpoint_period,
            prediction_checkpoint_period=args.prediction_checkpoint_period,
            epochs=args.epochs,
        )

    # 42 images for 2d, 15 images for 3d
    img_num = 42

    if '3d' in args.log_folder:
        img_num = 15

    # Plot performance
    exp.plot_performance().plot_prediction(
        masked_images=[i for i in range(img_num)])
Ejemplo n.º 7
0
"""
Example of running a single experiment of unet in the head and neck data.
The json config of the main model is 'examples/json/unet-sample-config.json'
All experiment outputs are stored in '../../hn_perf/logs'.
After running 3 epochs, the performance of the training process can be accessed
as log file and perforamance plot.
In addition, we can peek the result of 42 first images from prediction set.
"""

from deoxys.experiment import Experiment
from deoxys.utils import read_file

if __name__ == '__main__':

    Experiment(log_base_path='../../hn_perf/unet_test').from_full_config(
        'config/local_2d_unet_CT_W_PET.json').run_experiment(
            train_history_log=True,
            model_checkpoint_period=1,
            prediction_checkpoint_period=1,
            epochs=5).plot_performance().plot_prediction(
                masked_images=[i for i in range(6, 42)])
Ejemplo n.º 8
0
"""
To use comet.ml, uncomment this line
"""
###############################################
# from comet_ml import Experiment as CometEx
###############################################
from deoxys.experiment import Experiment
from deoxys.utils import read_file

if __name__ == '__main__':
    """
    To use comet.ml, uncomment this line
    """
    ######################################################################
    # # Create an experiment with your api key
    # experiment = CometEx(api_key="YOUR_API_KEY",
    #                      project_name="YOUR_PROJECT_NAME",
    #                      workspace="YOUR_WORKSPACE")
    ######################################################################
    config = read_file('examples/json/sequential-config.json')

    Experiment(log_base_path='../../mnist/logs').from_full_config(
        config).run_experiment()
Ejemplo n.º 9
0
def test_run_test():
    Experiment(log_base_path='../../oxford_perf/logs',
               best_model_monitors=[
                   'val_loss', 'val_accuracy'
               ]).from_file('tests/h5_files/model.002.h5').run_test(
                   masked_images=[i for i in range(3)])
Ejemplo n.º 10
0
from deoxys.experiment import Experiment
from deoxys.utils import read_file

if __name__ == '__main__':

    config = read_file('examples/json/oxford-pet-config.json')

    exp = Experiment(
        log_base_path='../../oxford_perf/logs',
        best_model_monitors=[
            'val_loss', 'val_accuracy', 'val_binary_fbeta', 'val_fbeta'
        ]).from_full_config(config).run_experiment(
            train_history_log=True,
            model_checkpoint_period=5,
            prediction_checkpoint_period=5,
            epochs=30).run_experiment(
                model_checkpoint_period=2,
                prediction_checkpoint_period=2,
                epochs=10,
                initial_epoch=30).plot_performance().plot_prediction(
                    masked_images=[i for i in range(10)], ).plot_prediction(
                        [i for i in range(20)],
                        img_name='Prediction_{index:02d}_contour.png',
                        contour=True).plot_prediction(
                            [i for i in range(20)],
                            img_name='Prediction_{index:02d}.png',
                            contour=False)

    # Best model in this run
    print(exp.best_model())
Ejemplo n.º 11
0
from deoxys.model import model_from_full_config
import matplotlib.pyplot as plt

from deoxys.loaders.architecture import BaseModelLoader
from tensorflow.keras.models import Model as KerasModel
from tensorflow.keras.layers import Input, concatenate
from tensorflow.keras.models import Sequential
from tensorflow import image
import tensorflow as tf
from tensorflow.keras.callbacks import TensorBoard
import tensorboard
import numpy as np
import scipy.ndimage
import math
from deoxys.model.layers import layer_from_config
from deoxys.customize import custom_architecture
import os
import h5py

if __name__ == '__main__':

    #ex_comet = ex(api_key="zoPcSaPo6mhKthsM8SOcgq9Uk",project_name="masterthesisafreen", workspace="afreen3010")
    #
    config = read_file('json/layer_32_filter_new.json')
    experiment = Experiment()
    #
    #from pdb import set_trace; set_trace()
    experiment.from_full_config(config).run_experiment(
        train_history_log=True, model_checkpoint_period=10,
        epochs=100).plot_performance()
# from comet_ml import Experiment as CometEx
import tensorflow as tf
import customize_obj

if __name__ == '__main__':
    if not tf.test.is_gpu_available():
        raise RuntimeError("GPU Unavailable")

    parser = argparse.ArgumentParser()
    parser.add_argument("config_file")
    parser.add_argument("log_folder")
    parser.add_argument("--epochs", default=500, type=int)
    parser.add_argument("--model_checkpoint_period", default=25, type=int)
    parser.add_argument("--prediction_checkpoint_period", default=25, type=int)

    args = parser.parse_args()

    # config = read_file(args.config_file)
    if os.path.isfile(args.config_file) and args.config_file.endswith('h5'):
        initial_epoch = int(args.config_file[-6:-3])
    else:
        raise RuntimeError('Not a model file')
    (Experiment(log_base_path=args.log_folder).from_file(
        args.config_file).run_experiment(
            train_history_log=True,
            model_checkpoint_period=args.model_checkpoint_period,
            prediction_checkpoint_period=args.prediction_checkpoint_period,
            epochs=args.epochs + initial_epoch,
            initial_epoch=initial_epoch).plot_performance().plot_prediction(
                masked_images=[i for i in range(42)]))
Ejemplo n.º 13
0
"""
Example of running a single experiment of unet in the head and neck data.
The json config of the main model is 'examples/json/unet-sample-config.json'
All experiment outputs are stored in '../../hn_perf/logs'.
After running 3 epochs, the performance of the training process can be accessed
as log file and perforamance plot.
In addition, we can peek the result of 42 first images from prediction set.
"""

from deoxys.experiment import Experiment
from deoxys.utils import read_file

if __name__ == '__main__':

    config = read_file('examples/json/unet-sample-config.json')

    Experiment(log_base_path='../../hn_perf/logs').from_full_config(
        config).run_experiment(train_history_log=True,
                               model_checkpoint_period=1,
                               prediction_checkpoint_period=1,
                               epochs=5).plot_performance().plot_prediction(
                                   masked_images=[i for i in range(42)])
Ejemplo n.º 14
0
configured in ../config/file_name.json
"""

from deoxys.experiment import Experiment
from deoxys.utils import read_file
import argparse
import tensorflow as tf

if __name__ == '__main__':
    if not tf.test.is_gpu_available():
        raise RuntimeError("GPU Unavailable")

    parser = argparse.ArgumentParser()
    parser.add_argument("config_file")
    parser.add_argument("log_folder")
    parser.add_argument("--epochs", default=500, type=int)
    parser.add_argument("--model_checkpoint_period", default=25, type=int)
    parser.add_argument("--prediction_checkpoint_period", default=25, type=int)

    args = parser.parse_args()

    config = read_file(args.config_file)

    exp = Experiment(
        log_base_path=args.log_folder).from_full_config(config).run_experiment(
            train_history_log=True,
            model_checkpoint_period=args.model_checkpoint_period,
            prediction_checkpoint_period=args.prediction_checkpoint_period,
            epochs=args.epochs,
        )