Пример #1
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    args = get_args()
    config = process_config(args.config)

    # if hasattr(config,"comet_api_key"):
    #     from comet_ml import Experiment

    # create the experiments dirs
    create_dirs([
        config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir,
        config.preprocessor.data_dir
    ])

    print('Creating the preprocessor.')
    preprocessor = factory.create("preprocessors." +
                                  config.preprocessor.name)(config)
    preprocessor.preprocess()

    print('Create the data generator.')
    data_loader = factory.create("data_loaders." +
                                 config.data_loader.name)(config)

    print('Create the model.')
    model = factory.create("models." + config.model.name)(config)

    print('Create the trainer')
    trainer = factory.create("trainers." + config.trainer.name)(
        model.model, data_loader.get_train_data(), config)

    print('Start training the model.')
    trainer.train()
Пример #2
0
def main(model_dir):
    tf_config = tf.ConfigProto()
    tf_config.gpu_options.allow_growth = True
    set_session(tf.Session(config=tf_config))

    config = os.path.join(model_dir, "config.json")
    config_path = config

    # process the json configuration file
    config = process_config(config_path)
    config.trainer.batch_size = 1

    print('Create the data generator.')
    data_loader = factory.create("data_loader." +
                                 config.data_loader.name)(config)

    print('Create the model.')
    model = factory.create("models." + config.model.name)(config)

    print('Create the trainer')
    trainer = BaseTrain(model.build_model(), data_loader, config)

    # checkpoint_path = os.path.join(constants.ROOT_FOLDER, config.callbacks.checkpoint_dir, config.exp.name + ".hdf5")
    checkpoint_path = os.path.join(model_dir, "model.hdf5")
    model.load(checkpoint_path)
    scores_dict = trainer.evaluate()
    for metric in scores_dict:
        open(os.path.join(model_dir, metric + ".txt"),
             "w").write(str(scores_dict[metric]))
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        amp, sr = librosa.load(config.predictor.predict_file_path, sr=8000)
        amp = audio_norm(amp)  # normalize
        if amp.shape[0] < config.model.duration * sr:
            # 왼쪽 오른쪽 똑같은 크기로 reflect
            amp = np.pad(amp,
                         int(np.ceil((10 * sr - amp.shape[0]) / 2)),
                         mode='reflect')
        amp = amp[:config.model.duration * sr]
        data = np.expand_dims(amp, axis=0)
        data = np.expand_dims(data, axis=-1)

        print('Create the model.')
        model = factory.create("models." + config.model.name)(config)

        predictor = factory.create("predictors." + config.predictor.name)(
            model.model, data, config)
        predictor.predict()
        sys.stdout.flush()
    except Exception as e:
        print(e)
        sys.stdout.flush()
def run(config,args):
    copy_codebase(config)

    l = Logger(config)
    logger = l.get_logger(__name__)
    # Set the random seed
    tf.random.set_random_seed(config.data_loader.random_seed)
    # Create the tensorflow session
    sess = tf.Session()
    # Create the dataloader
    data = create("data_loader." + config.data_loader.name)(config)
    # Create the model instance
    model = create("models.32." + config.model.name)(config)
    # Create the summarizer Object
    summarizer = create("utils." + config.log.name)(sess, config)
    # Create the trainer
    trainer = create("trainers." + config.trainer.name)(sess, model, data, config, summarizer)
    # Load model if exists
    model.load(sess)
    # Train the model
    if args.train:
        trainer.train()
    # Test the model
    if config.trainer.test_at_end:
        trainer.test()
    logger.info("Experiment has ended.")
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        # create the experiments dirs
        create_dirs([
            config.callbacks.tensorboard_log_dir,
            config.callbacks.checkpoint_dir
        ])

        print('Create the data generator.')
        data_loader = factory.create("data_loader." +
                                     config.data_loader.name)(config)

        print('Create the model.')
        model = factory.create("models." + config.model.name)(config)

        print('Create the trainer')
        trainer = factory.create("trainers." + config.trainer.name)(
            model.model, data_loader.get_train_data(), config)

        print('Start training the model.')
        trainer.train()

    except Exception as e:
        print(e)
        sys.exit(1)
Пример #6
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        # create the experiments dirs
        create_dirs([config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir])

        print('Create the data generator.')
        data_loader = factory.create("data_loader."+config.data_loader.name)(config)

        print('Create the model.')
        model = factory.create("models."+config.model.name)(config)

        if config.skip_train!=True:
            print('Create the trainer')
            trainer = factory.create("trainers."+config.trainer.name)(model.model, data_loader.get_train_data(), config)

            print('Start training the model.')
            trainer.train()
        
        # evaluator = factory.create("evaluators."+config.evaluator.name)(model.model, data_loader.get_test_data(), config)
        # evaluator.evaluate()
        evaluator = factory.create("evaluators."+config.evaluator.name)(model.model, data_loader.get_test_data(), config)
        
        result, y = evaluator.evaluate()
        result_idx = np.argmax(result,axis=1)
        y_idx = np.argmax(y,axis=1)
        print(classification_report(result_idx, y_idx))
    except Exception as e:
        print(e)
        sys.exit(1)
Пример #7
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([
        os.path.join('/scratch/users/thomaslj/autogen_files',
                     config.model.bash_name,
                     config.callbacks.tensorboard_log_dir),
        os.path.join('/scratch/users/thomaslj/autogen_files',
                     config.model.bash_name, config.callbacks.checkpoint_dir)
    ])

    print('Create the data generator.')
    logger('Creating data generators ...'.format(datetime.now()))
    data_loader = {
        'train':
        factory.create("data_loader." + config.data_loader.name)(
            config, subset='train', shuffle=True),
        'test':
        factory.create("data_loader." + config.data_loader.name)(
            config, subset='test'),
        'eval':
        factory.create("data_loader." + config.data_loader.name)(config,
                                                                 subset='eval')
    }

    print('Create the model.')
    model = TemporalClustering(config)
    logger('Creating the trainer ...'.format(datetime.now()))
    if config.model.num_gpus > 1:
        trainer = factory.create("trainers." + config.trainer.name)(
            model.parallel_model, data_loader, config)
    else:
        trainer = factory.create("trainers." + config.trainer.name)(
            model.model, data_loader, config)

    print('Start training the model.')
    trainer.train()
    print('predicting the autoencoder')
    trainer.predict_autoencoder()

    print('Computing the clustering layer.')
    data_loader['train'].model_type = data_loader[
        'test'].model_type = data_loader['eval'].model_type = 'clustering'
    trainer.data_groups['train_data'].model_type = trainer.data_groups['test_data'].model_type = \
        trainer.data_groups['eval_data'].model_type = trainer.eval_data.model_type = trainer.test_data.model_type = \
        trainer.test_data.model_type = 'clustering'
    clust_layer = trainer.clustering_layer()
    def __init__(self, config):
        super(CifarDeepClusterModel, self).__init__(config)
        self.model_builder = create("tensorflow.keras.applications.{}".format(
            self.config.model.backbone))

        optimizer_builder = create("tensorflow.keras.optimizers.{}".format(
            self.config.model.optimizer, ))
        self.optimizer = optimizer_builder(
            learning_rate=self.config.model.learning_rate,
            momentum=self.config.model.momentum)

        print("[DEBUG] Building model.")
        self.build_model()
Пример #9
0
def main():
    ##########################################################
    # TensorFlow configuration
    tf_config = tf.ConfigProto()
    tf_config.gpu_options.allow_growth = True
    k.tensorflow_backend.set_session(tf.Session(config=tf_config))
    ##########################################################

    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        # create the experiments dirs
        create_dirs([
            config.callbacks.tensorboard_log_dir,
            config.callbacks.checkpoint_dir
        ])

        logger('Creating data generators ...'.format(datetime.now()))
        data_loader = {
            'train':
            factory.create("data_loader." + config.data_loader.name)(
                config, subset='train', shuffle=True),
            'eval':
            factory.create("data_loader." + config.data_loader.name)(
                config, subset='eval')
        }

        logger('Creating the model ...'.format(datetime.now()))
        model = factory.create("models." + config.model.name)(config)

        logger('Creating the trainer ...'.format(datetime.now()))
        if config.model.num_gpus > 1:
            trainer = factory.create("trainers." + config.trainer.name)(
                model.parallel_model, data_loader, config)
        else:
            trainer = factory.create("trainers." + config.trainer.name)(
                model.model, data_loader, config)

        logger('Starting model training ...'.format(datetime.now()))
        trainer.train()

        logger('Training has finished!'.format(datetime.now()))

    except Exception as e:
        logger(e)
        sys.exit(1)
Пример #10
0
def main(memory_frac, config, target_file):

    if memory_frac is None:
        tf_config = tf.ConfigProto()
        tf_config.gpu_options.allow_growth = True
        set_session(tf.Session(config=tf_config))
    else:
        tf_config = tf.ConfigProto()
        tf_config.gpu_options.per_process_gpu_memory_fraction = memory_frac
        set_session(tf.Session(config=tf_config))

    config_path = config

    # process the json configuration file
    config = process_config(config_path)

    print('Create the model.')
    model = factory.create("models." + config.model.name)(config)

    # checkpoint_path = os.path.join(constants.ROOT_FOLDER, config.callbacks.checkpoint_dir, config.exp.name + ".hdf5")
    checkpoint_path = "/Users/daniel/myWork/masters_thesis/experiments/dnn_dense_1024_adam_0.001_32/" \
                      "2018-06-06-19-21-29/checkpoints/dnn.hdf5"
    print(checkpoint_path)
    predictor = ModelPredictor(config, checkpoint_path)

    predictor.predict(target_file)
Пример #11
0
def main():

    try:
        args = get_args()
        config = process_config(args.config)

        logger = configure_logger(level=logging.DEBUG)
        logger.info('Starting train.py...')
        logger.debug(config)

        # create the experiments dirs
        create_dirs([config.callbacks.checkpoint_dir])

        logger.info('Creating the data generator.')
        data_loader = factory.create("data_loaders." +
                                     config.data_loader.name)(config)

        # For this project the number of classes is only known
        # at runtime so we add that to the configuration.
        config.n_classes = data_loader.n_classes
        logger.debug('Running with {} classes.'.format(config.n_classes))

        logger.info('Creating model.')
        model = factory.create("models." + config.model.name)(config)

        logging.info('Creating trainer')
        trainer = factory.create("trainers." + config.trainer.name)(
            model, data_loader, config)

        logging.info('Running trainer')
        trainer.train()

        logging.info('Loading evaluators')
        evaluators = []
        for evaluator in config.evaluators:
            evaluators.append(
                factory.create("evaluators." + evaluator.name)(model,
                                                               data_loader,
                                                               evaluator))

        logging.info('Evaluating...')
        for evaluator in evaluators:
            evaluator.evaluate()

    except Exception as e:
        print(e)
        sys.exit(1)
Пример #12
0
    def __init__(self, config):
        super(PretrainedModel, self).__init__(config)

        self.logger = logging.getLogger('train')
        self.logger.info("Done configuring PretrainedModel")

        self.model_builder = create("tensorflow.keras.applications.{}".format(
            self.config.model.backbone))
        self.build_model()
Пример #13
0
def run():
    # Get the arguments
    args = get_args()

    config, _ = get_config_from_json(args.config)
    config.exp.name = args.experiment
    config = process_config(config)
    # create the experiments dirs
    create_dirs([
        config.log.summary_dir,
        config.log.checkpoint_dir,
        config.log.step_generation_dir,
        config.log.log_file_dir,
        config.log.codebase_dir,
    ])

    # Copy the model code and the trainer code to the experiment folder
    copy_codebase(config)

    l = Logger(config)
    logger = l.get_logger(__name__)
    # Set the random seed
    tf.random.set_random_seed(config.data_loader.random_seed)
    # Create the tensorflow session
    sess = tf.Session()
    # Create the dataloader
    data = create("data_loader." + config.data_loader.name)(config)
    # Create the model instance
    model = create("models.{}.".format(config.data_loader.image_size) +
                   config.model.name)(config)
    # Create the summarizer Object
    summarizer = create("utils." + config.log.name)(sess, config)
    # Create the trainer
    trainer = create("trainers." + config.trainer.name)(sess, model, data,
                                                        config, summarizer)
    # Load model if exists
    model.load(sess)
    # Train the model
    if args.train:
        trainer.train()
    # Test the model
    if config.trainer.test_at_end:
        trainer.test()
    logger.info("Experiment has ended.")
Пример #14
0
def load_model():
    global model
    set_session(sess)
    model = factory.create("models." + config.model.name)(config)
    model = model.model
    model.load_weights(config.predictor.predict_model)

    model.compile(optimizer=config.model.optimizer,
                  loss='categorical_crossentropy',
                  metrics=['acc'])
    model._make_predict_function()
    def __init__(self, config):
        super(CifarDataLoader, self).__init__(config)

        if 'preprocessing_function' in self.config.data_loader.toDict():
            self.preprocess_func = create(
                "tensorflow.keras.applications.{}".format(
                    self.config.data_loader.preprocessing_function))
        else:
            self.preprocess_func = lambda x: x / 255.

        self.load()
        self.preprocess()
Пример #16
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill

    try:
        args = get_args()
        config, config_dict = process_config(args.config)

    except:
        print("missing or invalid arguments")
        exit(0)

    # create the experiments dirs
    create_dirs([config.summary_dir, config.checkpoint_dir])

    with open(os.path.join(config.experiment_dir, 'config.json'), 'w') as fp:
        json.dump(config, fp)

    print('Create the data generator.')
    data = factory.create("data_loaders." + config.data['name'])(config)

    print('Create the model.')
    model = factory.create("models." + config.model['name'])(config)

    # create tensorflow session
    tfconfig = tf.ConfigProto()
    tfconfig.gpu_options.allow_growth = True
    sess = tf.Session(config=tfconfig)

    # create tensorboard logger
    logger = Logger(sess, config)

    print('Create the trainer')
    trainer = factory.create("trainers." + config.trainer['name'])(sess, model,
                                                                   data,
                                                                   config,
                                                                   logger)

    print('Start training the model.')
    trainer.train()
Пример #17
0
def main():

    try:
        args = get_args()
        list_config_files = os.listdir(args.config)
        if len(list_config_files) == 0:
            raise Exception('Empty config directory !')
        
        #for each config train
        for cf in list_config_files:
            print(f'Processing Config File : {cf}')
            path_to_config = os.path.join(args.config,cf)
            config = process_config(path_to_config)

            create_dirs([config.callbacks.checkpoint_dir])

            #print('Create the data generator.')
            data_loader = factory.create("data_loader."+config.data_loader.name)(config,config.exp.data_dir)
            #print('Create the model.')
            model = factory.create("models."+config.model.name)(config,data_loader.feature_columns)
            #print('Create the trainer')
            trainer = factory.create("trainers."+config.trainer.name)(model.model, data_loader.get_train_data(),data_loader.get_validation_data(), config)
            #print('Start training the model.')
            trainer.train()
            #print('Max val acc: ',max(trainer.val_acc))
        if args.evaluate == 't':
                #print('Evaluating..')
                path_to_models = config.callbacks.exp_dir
                print(path_to_models)
                test_x, test_y = data_loader.get_testing_data()
                best_model_path = evaluate_test(path_to_models,test_x, test_y)
        
        #submit kaggle predictions
        if args.submit == 't':
                pass

    except Exception as e:
        print(e)
        sys.exit(1)
Пример #18
0
def main(memory_frac, config, model_type):

    if memory_frac is None:
        tf_config = tf.ConfigProto()
        tf_config.gpu_options.allow_growth = True
        set_session(tf.Session(config=tf_config))
    else:
        tf_config = tf.ConfigProto()
        tf_config.gpu_options.per_process_gpu_memory_fraction = memory_frac
        set_session(tf.Session(config=tf_config))
    if model_type is None and config is None:
        print("Pass either --model_type argument or --config argument")
        sys.exit(1)
    if model_type is not None:
        config_path = get_config_for_model(model_type)
    else:
        config_path = config

    # process the json configuration file
    config = process_config(config_path)

    # create the experiments dirs
    create_dirs([config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir, config.callbacks.model_dir,
                 config.callbacks.config_dir, config.callbacks.result_dir])

    copyfile(config_path, os.path.join(config.callbacks.config_dir, "config.json"))

    print('Create the data generator.')
    data_loader = factory.create("data_loader." + config.data_loader.name)(config)

    print('Create the model.')
    model = factory.create("models." + config.model.name)(config)
    copyfile(inspect.getfile(model.__class__), os.path.join(config.callbacks.model_dir, "model.py"))

    print('Create the trainer')
    trainer = BaseTrain(model.build_model(), data_loader, config)

    print('Start training the model.')
    trainer.train()
Пример #19
0
def main():

    try:
        args = get_args()
        config = process_config(args.config)

        # create the experiments dirs
        create_dirs([config.callbacks.checkpoint_dir])

        print('Create the data generator.')
        data_loader = factory.create("data_loader." +
                                     config.data_loader.name)(config)

        print('Create the model.')
        model = factory.create("models." + config.model.name)(config)

        print('Create the trainer')
        trainer = factory.create("trainers." + config.trainer.name)(
            model, data_loader, config)

        print('Loading evaluators')
        evaluators = []
        for evaluator in config.evaluators:
            evaluators.append(
                factory.create("evaluators." + evaluator.name)(model,
                                                               data_loader,
                                                               evaluator))

        print('Start training the model.')
        trainer.train()

        print('Evaluating...')
        for evaluator in evaluators:
            evaluator.evaluate()

    except Exception as e:
        print(e)
        sys.exit(1)
Пример #20
0
def main():

    # capture the config path from the run arguments
    # then process the json configuration fill
    try:
        args = get_args()
        config = process_config(args.config)

        # create the experiments dirs
        create_dirs([
            config.callbacks.tensorboard_log_dir,
            config.callbacks.checkpoint_dir,
        ])

        print("Create the data generator.")
        data_loader = factory.create("VisionEngine.data_loaders." +
                                     config.data_loader.name)(config)

        print("Create the model.")
        model = factory.create("VisionEngine.models." +
                               config.model.name)(config)

        if config.model.loadckpt:
            print("loading model checkpoint")
            model.load(config.model.ckpt_path)

        print("Create the trainer")
        trainer = factory.create("VisionEngine.trainers." +
                                 config.trainer.name)(
                                     model.model, data_loader.get_train_data(),
                                     config)

        print("Start training the model.")
        trainer.train()

    except Exception as e:
        print(e)
        sys.exit(1)
Пример #21
0
 def _setup_preprocessing(self):
     """ Setup the preprocessing function specified in the
     configuration or use a 0-1 normalization if none is 
     present. """
     if 'preprocessing_func' in self.config.data_loader.toDict():
         self.preprocess_func = create(
             "tensorflow.keras.applications.{}".format(
                 self.config.data_loader.preprocessing_func))
         self.logger.debug("Loaded {} for preprocessing".format(
             self.config.data_loader.preprocessing_func))
     else:
         self.preprocess_func = lambda x: x / 255.
         self.logger.debug(
             "Using standard 0-1 normalization as preprocessing.")
def evaluation(config, visualization=False):
    # Data generator creation
    datagen = SegmentationDataGenerator(config, is_training_set=False)

    # dynamic model instanciation
    network = None
    network = factory.create(config.model.class_name)(config, datagen)

    # Load weight file in model
    load_weights(network.model, config)

    if visualization:
        qualitative(network.model, config, datagen)
    else:
        quantitative(network.model, config, datagen)
Пример #23
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # use mixed precision for training
    if config.exp.mixed_precision:
        print('Use mixed precision training')
        policy = mixed_precision.Policy('mixed_float16')
        mixed_precision.set_policy(policy)

    if config.exp.jpa_optimization:
        tf.config.optimizer.set_jit(True)

    # create the experiments dirs
    create_dirs([
        config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir
    ])

    print('Create the training data generator.')
    if config.generator.is_scenenet == True:
        train_data = ScenenetRGBDDataGenerator(config)
    else:
        train_data = JointDataGenerator(config)

    validation_data = None
    if type(config.validation.img_dir) == str:
        print('Create the validation data generator.')
        validation_data = JointDataGenerator(config, is_training_set=False)

    print('Create the model.')
    model = factory.create(config.model.class_name)(config, train_data)

    print('Create the trainer')
    trainer = SegmentationTrainer(model,
                                  train_data,
                                  config,
                                  validation_generator=validation_data)

    print('Start training the model.')
    trainer.train()
Пример #24
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration fill
    args = get_args()
    config = process_config(args.config)

    # if hasattr(config,"comet_api_key"):
    #     from comet_ml import Experiment

    # create the experiments dirs
    create_dirs([
        config.callbacks.tensorboard_log_dir, config.callbacks.checkpoint_dir,
        config.preprocessor.data_dir
    ])

    print('Creating the preprocessor.')
    preprocessor = factory.create("preprocessors." +
                                  config.preprocessor.name)(config)
    preprocessor.preprocess()
Пример #25
0
    def __init__(self, config):
        super(PretrainedKMeansModel, self).__init__(config)

        self.logger = logging.getLogger('train')
        self.logger.info("Done configuring PretrainedKMeansModel")

        self.model_builder = create("tensorflow.keras.applications.{}".format(
            self.config.model.backbone
        ))

        # Set the number of clusters, but with the
        # condition that if the number is "auto", we set
        # the number to the number of classes.
        if self.config.model.n_clusters == "auto":
            self.n_clusters = self.config.n_classes
        else:
            self.n_clusters = self.config.model.n_clusters

        self.logger.info("PretrainedKMeansModel setup using {} clusters.".format(
            self.n_clusters
        ))
        self.build_model()
Пример #26
0
def main():
    # capture the config path from the run arguments
    # then process the json configuration file
    try:
        args = get_args()
        config = process_config(args.config)
    except:
        print("missing or invalid arguments")
        exit(0)

    # Force some parameters from configuration
    config.generator.use_data_augmentation = False
    config.trainer.batch_size = 1

    # Data generator creation
    datagen = DepthDataGenerator(config, is_training_set=False)

    network = factory.create(config.model.class_name)(config, datagen)

    # Load weight file in model
    load_weights(network.model, config)

    visualize_results(network.model, config, datagen)
Пример #27
0
from models.GAN_GPU import GAN

from utils.config import process_config
from utils.dirs import create_dirs, create_dir
from utils.args import get_args
from utils.logger import get_logger
from utils import factory

import tensorflow as tf
from bunch import Bunch

log = get_logger()

config, config_dict = process_config("configs/wgan_opt.json")

data = factory.create("data_loaders." + config.data['name'])(config)

config_opt = []
config_opt.append([
    Categorical(categories=[128, 256, 512, 1024], name='d_num_filters'),
    config.arch["d_num_filters"]
])
config_opt.append([
    Categorical(categories=[False, True], name='d_batch_norm'),
    config.arch["d_batch_norm"]
])
config_opt.append([
    Categorical(categories=[False, True], name='g_batch_norm'),
    config.arch["g_batch_norm"]
])
config_opt.append([
Пример #28
0
 def __init__(self, config):
     super(CifarPretrainedModel, self).__init__(config)
     self.model_builder = create("tensorflow.keras.applications.{}".format(
         self.config.model.backbone
     ))
     self.build_model()
Пример #29
0
MIN_LR = 1e-10
MAX_LR = 10
NUM_EPOCHS = 30
MODEL_TASK = "RGBD"
config.generator.use_data_augmentation = False  # force no data augmentation
config.model.lr.policy = "mdr"  # force no special lr scheduler
datagen = None
if MODEL_TASK == "RGB":
    datagen = SegmentationDataGenerator(config)
elif MODEL_TASK == "D":
    datagen = DepthDataGenerator(config)
else:
    datagen = JointDataGenerator(config)

network = factory.create(config.model.class_name)(config, datagen)

# initialize the learning rate finder and then train with learning
# rates ranging from 1e-10 to 1e+1
print("[INFO] finding learning rate...")
lrf = LearningRateFinder(network.model)
lrf.find(datagen,
         MIN_LR,
         MAX_LR,
         stepsPerEpoch=datagen.__len__(),
         batchSize=config.trainer.batch_size,
         epochs=NUM_EPOCHS)

# plot the loss for the various learning rates and save the
# resulting plot to disk
lrf.plot_loss()
Пример #30
0
 def build_model(self):
     print('Create the model.')
     self.model = factory.create("models." + self.config.model.name)(self.config).build_model()