Exemplo n.º 1
0
def load_model(model_name, activation='relu', input_shape=200):

    if model_name == 'cnn-50':
        from model_zoo import cnn_model
        model = cnn_model.model([50, 2], activation, input_shape)

    elif model_name == 'cnn-2':
        from model_zoo import cnn_model
        model = cnn_model.model([2, 50], activation, input_shape)

    elif model_name == 'cnn-deep':
        from model_zoo import cnn_deep
        model = cnn_deep.model(activation, input_shape)

    elif model_name == 'cnn-local':
        from model_zoo import cnn_local
        model = cnn_local.model(activation)

    elif model_name == 'cnn-dist':
        from model_zoo import cnn_dist
        model = cnn_dist.model(activation)

    elif model_name == 'basset':
        from model_zoo import basset
        model = basset.model(activation)

    elif model_name == 'residualbind':
        from model_zoo import residualbind
        model = residualbind.model(activation)

    return model
Exemplo n.º 2
0
results_path = helper.make_directory('../results', args.o)

#-----------------------------------------------------------------
# load data
data_path = '../data'
filepath = os.path.join(data_path, 'synthetic_code_dataset.h5')
x_train, y_train, x_valid, y_valid, x_test, y_test, model_test = helper.load_data(
    filepath)
N, L, A = x_train.shape
num_labels = y_train.shape[1]

#-----------------------------------------------------------------
# create model
model = genome_model.model(input_shape=(L, A),
                           num_labels=1,
                           activation=activation,
                           dropout=dropout,
                           bn=bn,
                           l2=None)
loss = keras.losses.BinaryCrossentropy(from_logits=False, label_smoothing=0.0)
optimizer = keras.optimizers.Adam(learning_rate=0.001)

#-----------------------------------------------------------------
# Fit model
attacker = tfomics.attack.PGDAttack((batch_size, L, A),
                                    model,
                                    loss,
                                    learning_rate=0.01,
                                    epsilon=epsilon,
                                    num_steps=num_steps)
history, trainer = tfomics.fit.fit_robust(model,
                                          loss,