Exemple #1
0
def run_routine_resnet(config, verbose=(2,2), nb_epoch_finetune=15, nb_epoch_after=50,
                       stiefel_observed=None, stiefel_lr=0.01):
    """
    Finetune the ResNet-DCov

    Returns
    -------

    """
    image_gen = ImageDataGeneratorAdvanced(TARGET_SIZE, RESCALE_SMALL, True,
                                           horizontal_flip=True,
                                           )
    monitor_class = (O2Transform, SecondaryStatistic)
    # monitor_metrics = ['weight_norm',]
    # monitor_metrics = ['output_norm',]
    monitor_metrics = ['matrix_image',]
    if stiefel_observed is None:
        run_finetune(ResNet50_o2, mincorig_finetune,
                     nb_classes=nb_classes,
                     input_shape=input_shape, config=config,
                     nb_epoch_finetune=nb_epoch_finetune, nb_epoch_after=nb_epoch_after,
                     image_gen=image_gen, title='minc_orig_resnet50', verbose=verbose,
                     monitor_classes=monitor_class,
                     monitor_measures=monitor_metrics)
    else:
        run_finetune_with_Stiefel_layer(ResNet50_o2, mincorig_finetune,
                                        nb_classes=nb_classes,
                                        input_shape=input_shape, config=config,
                                        nb_epoch_finetune=nb_epoch_finetune, nb_epoch_after=nb_epoch_after,
                                        image_gen=image_gen, title='minc_orig_resnet50_stiefel', verbose=verbose,
                                        monitor_classes=monitor_class,
                                        monitor_measures=monitor_metrics,
                                        observed_keywords=stiefel_observed,
                                        lr=stiefel_lr)
Exemple #2
0
def run_model_with_config(model,
                          config,
                          title='cifar10',
                          image_gen=None,
                          verbose=(2, 2),
                          nb_epoch_finetune=15,
                          nb_epoch_after=50,
                          stiefel_observed=None,
                          stiefel_lr=0.01,
                          weight_norm=False,
                          lr_decay=False):
    """
    Finetune the ResNet-DCov

    Returns
    -------

    """

    monitor_class = (O2Transform, SecondaryStatistic)
    # monitor_metrics = ['weight_norm',]
    # monitor_metrics = ['output_norm',]
    monitor_metrics = [
        'matrix_image',
    ]
    if stiefel_observed is None:
        if weight_norm:
            run_finetune_with_weight_norm(model,
                                          cifar_train,
                                          nb_classes=nb_classes,
                                          input_shape=input_shape,
                                          config=config,
                                          nb_epoch_finetune=nb_epoch_finetune,
                                          nb_epoch_after=nb_epoch_after,
                                          image_gen=image_gen,
                                          title=title + '-weight_norm',
                                          verbose=verbose,
                                          monitor_classes=monitor_class,
                                          monitor_measures=monitor_metrics,
                                          lr_decay=lr_decay)
        run_finetune(model,
                     cifar_train,
                     nb_classes=nb_classes,
                     input_shape=input_shape,
                     config=config,
                     nb_epoch_finetune=nb_epoch_finetune,
                     nb_epoch_after=nb_epoch_after,
                     image_gen=image_gen,
                     title=title,
                     verbose=verbose,
                     monitor_classes=monitor_class,
                     monitor_measures=monitor_metrics,
                     lr_decay=lr_decay)
    else:
        run_finetune_with_Stiefel_layer(model,
                                        cifar_train,
                                        nb_classes=nb_classes,
                                        input_shape=input_shape,
                                        config=config,
                                        nb_epoch_finetune=nb_epoch_finetune,
                                        nb_epoch_after=nb_epoch_after,
                                        image_gen=image_gen,
                                        title=title + "-stiefel",
                                        verbose=verbose,
                                        monitor_classes=monitor_class,
                                        monitor_measures=monitor_metrics,
                                        observed_keywords=stiefel_observed,
                                        lr=stiefel_lr,
                                        lr_decay=lr_decay)