Ejemplo n.º 1
0
    return lr


INCV_lr_callback = LearningRateScheduler(INCV_lr_schedule)

## DONE

# Define optimizer and compile model
optimizer = optimizers.Adam(lr=INCV_lr_schedule(0),
                            beta_1=0.9,
                            beta_2=0.999,
                            epsilon=1e-08,
                            decay=0.0)
model = create_model(
    input_shape=input_shape,
    classes=n_classes,
    name=INCV_name,
    architecture='ResNet32'
)  ## this is the INCV model, that is the model used in INCV for generating a clean dataset.
model.compile(optimizer=optimizer,
              loss='categorical_crossentropy',
              metrics=['accuracy'])
weights_initial = model.get_weights()
# Print model architecture
print('Architecture of INCV-model:')
model.summary()

## DONE

##################################################################################################################################
""" INCV iteration """
    elif epoch > 80:
        lr *= 1e-1
    print('Learning rate: ', lr)
    return lr


lr_callback = LearningRateScheduler(lr_schedule)

# Define optimizer and compile model
optimizer = optimizers.Adam(lr_schedule(0),
                            beta_1=0.9,
                            beta_2=0.999,
                            epsilon=1e-08,
                            decay=0.0)
model = create_model(input_shape=input_shape,
                     classes=n_classes,
                     name=network,
                     architecture=network)
model.summary()

parallel_model = multi_gpu_model(model, gpus=2)
parallel_model.compile(optimizer=optimizer,
                       loss='categorical_crossentropy',
                       metrics=['accuracy'])

##################################################################################################################################
""" Main training """
results = parallel_model.fit_generator(
    datagen.flow(x_train[val1_idx, :],
                 y_train_noisy[val1_idx, :],
                 batch_size=batch_size),
    epochs=epochs,
Ejemplo n.º 3
0
def INCV_lr_schedule(epoch):
    # Learning Rate Schedule
    lr = 1e-3
    if epoch > 40:
        lr *= 0.1
    elif epoch > 30:
        lr *= 0.25
    elif epoch > 20:
        lr *= 0.5
    print('Learning rate: ', lr)
    return lr
INCV_lr_callback = LearningRateScheduler(INCV_lr_schedule)

# Define optimizer and compile model
optimizer = optimizers.Adam(lr=INCV_lr_schedule(0), beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model = create_model(input_shape=input_shape, classes=n_classes, name=INCV_name, architecture='ResNet32')
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics = ['accuracy'])
weights_initial = model.get_weights()
# Print model architecture
print('Architecture of INCV-model:')
model.summary()

##################################################################################################################################
""" INCV iteration """
train_idx = np.array([False for i in range(n_train)])
val_idx = np.array([True for i in range(n_train)])
INCV_save_best = True
for iter in range(1,INCV_iter+1):
    print('INCV iteration %d including first half and second half. In total %d iterations.'%(iter,INCV_iter))
    val_idx_int = np.array([i for i in range(n_train) if val_idx[i]]) # integer index
    np.random.shuffle(val_idx_int)
Ejemplo n.º 4
0
def INCV_lr_schedule(epoch):
    # Learning Rate Schedule
    lr = 1e-3
    if epoch > 40:
        lr *= 0.1
    elif epoch > 30:
        lr *= 0.25
    elif epoch > 20:
        lr *= 0.5
    print('Learning rate: ', lr)
    return lr
INCV_lr_callback = LearningRateScheduler(INCV_lr_schedule)

# Define optimizer and compile model
optimizer = optimizers.Adam(lr=INCV_lr_schedule(0), beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model = create_model(input_shape=input_shape, classes=n_classes, name='INCV_ResNet32', architecture='ResNet32')
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics = ['accuracy'])
weights_initial = model.get_weights()
# Print model architecture
print('Architecture of INCV-model:')
model.summary()

##################################################################################################################################
""" INCV iteration """
train_idx = np.array([False for i in range(n_train)])
val_idx = np.array([True for i in range(n_train)])
INCV_save_best = True
for iter in range(1,INCV_iter+1):
    print('INCV iteration %d including first half and second half. In total %d iterations.'%(iter,INCV_iter))
    val_idx_int = np.array([i for i in range(n_train) if val_idx[i]]) # integer index
    np.random.shuffle(val_idx_int)