Пример #1
0
def model_v3(exp_name,
             convtype='chebyshev5',
             pooltype='max',
             nmaps=16,
             activation_func='relu',
             stat_layer=None,
             input_channels=1,
             gc_depth=8,
             nfilters=64,
             const_k=5,
             var_k=None,
             filters=None,
             batch_norm_output=False,
             var_batch_norm=None,
             fc_layers=[],
             num_outputs=1,
             reg_factor=0,
             dropout_rate=0.8,
             verbose=True,
             num_epochs=1,
             learning_rate=1e-4,
             decay_factor=0.999,
             decay_freq=1,
             decay_staircase=False,
             loss_func="l1",
             nside=NSIDE,
             nsides=None,
             order=ORDER,
             batch_size=16):
    """
    Returns DeepSphere model object for v3 architectures.

    :param convtype: Type of graph convolution performed ("chebyshev5" or "monomials"). TODO: Figure out difference
    :param num_outputs: 1 for just sigma_8, 2 for sigma_8 and predicted log-variance q
    :param nsides: List of NSIDES for graph convolutional layers. Length = gc_depth
    :param nside: NSIDE of input maps. Should be 1024.
    :param loss_func: Choice of loss function ("l1", "custom1", "custom2", "l2"). Must be implemented in DeepSphere codebase.
    :param decay_staircase: If true, performs integer division in lr decay, decaying every decay_freq steps.
    :param decay_freq: If decay_staircase=true, acts to stagger decays. Otherwise, brings down decay factor.
    :param dropout_rate: Percentage of neurons kept. TODO: Figure out what layers this applies to.
    :param reg_factor: Multiplier for L2 Norm of weights. TODO: Figure out good value, implement more complex reg, and allow for adaptive scheduling.
    :param fc_layers: List of sizes of hidden fully connected layers (excluding the output layer).
    :param var_batch_norm: List of True/False values turning batch normalization on/off for each GC layer. TODO: Figure out how this works for FC layers.
    :param batch_norm_output: Batch normalization value for the output layer (True/False). Ununsed if var_batch_norm is not None.
    :param var_k: List of GC orders K for each layer. Length = gc_depth.
    :param const_k: Constant K value for each GC layer. Unused if var_k is not None.
    :param stat_layer: Type of statistical layer applied for invariance. Can be None, mean, meanvar, var, or hist.
    :param pooltype: Type of pooling used for GC layers (max or avg). TODO: Figure out which one is better.
    :param activation_func: Type of activation function applied for all GC and FC layers (relu, leaky_relu, elu, etc.). TODO: Figure out which one is best.
    :param gc_depth: Number of GC layers in the network. Fixed at eight if NSIDE=1024 and pooling by two every layer.
    :param filters: List of # of filters for each GC layer. Length = gc_depth.
    :param batch_size: Batch size for training the network. Ideally a power of two.
    :param nfilters: Constant # of filters for each GC layer. Unused if filters is not None.
    :param exp_name: Experiment ID to define and track directories.
    :param order: HEALPIX order for partial-sky maps. Fixed at 2. TODO: Is 4 better?
    :param decay_factor: Decay factor by which learning rate gets multiplied every decay_freq steps depending on decay_staircase. TODO: What to use?
    :param nmaps: Number of full-sky maps from which the training data is being generated.
    :param input_channels: Number of input partial-sky maps. 1 for convergence, 2 for shear, +1 for counts-in-cells.
    :param learning_rate: Initial learning rate to use during training
    :param num_epochs: Number of epochs for training the model
    :param verbose: Outputs information on model config

    :return: DeepSphere model for training on FLASK v2 data without galaxy-matter bias. Doesn't allow for sophisticated regularization or loss functions.
    """

    return models.deepsphere(**params_v3(
        exp_name, convtype, pooltype, nmaps, activation_func, stat_layer,
        input_channels, gc_depth, nfilters, const_k, var_k, filters,
        batch_norm_output, var_batch_norm, fc_layers, num_outputs, reg_factor,
        dropout_rate, verbose, num_epochs, learning_rate, decay_factor,
        decay_freq, decay_staircase, loss_func, nside, nsides, order,
        batch_size))
Пример #2
0
        lr, beta1=0.9, beta2=0.999, epsilon=1e-8)
    #     params['optimizer'] = lambda lr: tf.train.RMSPropOptimizer(lr, decay=0.9, momentum=0.)
    n_evaluations = 90
    params['eval_frequency'] = int(params['num_epochs'] * (training.N) /
                                   params['batch_size'] / n_evaluations)
    params['M'] = []
    params['Fseg'] = 3
    params['dense'] = True
    params['weighted'] = False
    #     params['profile'] = True
    params['dtype'] = tf.float32
    params['restore'] = True
    params['tf_dataset'] = training.get_tf_dataset(params['batch_size'],
                                                   dtype=np.float32)

    model = models.deepsphere(**params)

    acc_val, loss_val, loss_train, t_step, t_batch = model.fit(
        training, validation, use_tf_dataset=True, cache='TF', restore=restore)

    probabilities, _, _ = model.probs(test, 3, cache='TF')
    predictions, labels_test, loss = model.predict(test, cache='TF')

    AP = average_precision(probabilities, labels_test)
    mAP = np.mean(AP[1:])
    acc, macc = accuracy(predictions, labels_test)

    if os.path.isfile(filepath + '.npz'):
        file = np.load(filepath + '.npz')
        tb = file['tbatch'].tolist()
        avprec = file['AP'].tolist()