Exemplo n.º 1
0
siamese.compile(loss=contrastive_loss, optimizer=opt, metrics=['accuracy'])

#################
# Training Loop #
#################
siamese.fit_generator(
    generator=train_generator,
    steps_per_epoch=evaluate_every_n_batches,
    validation_data=valid_generator,
    validation_steps=100,
    epochs=num_epochs,
    workers=multiprocessing.cpu_count(),
    use_multiprocessing=True,
    callbacks=[
        # First generate custom n-shot classification metric
        NShotEvaluationCallback(
            num_evaluation_tasks,
            n_shot_classification,
            k_way_classification,
            valid,
            preprocessor=whiten_downsample,
        ),
        # Then log and checkpoint
        CSVLogger(PATH + '/logs/convnet_contrastive_loss.csv'),
        ModelCheckpoint(
            PATH + '/models/convnet_contrastive_loss.hdf5',
            monitor='val_{}-shot_acc'.format(n_shot_classification),
            mode='max',
            save_best_only=True,
            verbose=True)
    ])
Exemplo n.º 2
0
                            distance_metric='uniform_euclidean')
opt = Adam(clipnorm=1.)
siamese.compile(loss='binary_crossentropy',
                optimizer=opt,
                metrics=['accuracy'])
# plot_model(siamese, show_shapes=True, to_file=PATH + '/plots/siamese.png')
print(siamese.summary())

#################
# Training Loop #
#################
callbacks = [
    # First generate custom n-shot classification metric
    NShotEvaluationCallback(num_evaluation_tasks,
                            n_shot_classification,
                            k_way_classification,
                            valid,
                            preprocessor=batch_preprocessor),
    SiameseValidator(
        batch_gen=valid,
        num_tasks=num_evaluation_tasks,
        n_shot=1,
        k_way=2,  # number of speakers sampled
        metrics=val_metrics,
        monitor='pooled_eer',
        mode='min',
        preprocessor=batch_preprocessor),
    # Then log and checkpoint
    CSVLogger(os.path.join(PATH, 'logs/{}.csv'.format(param_str))),
    ModelCheckpoint(os.path.join(PATH, 'models/{}.hdf5'.format(param_str)),
                    monitor='pooled_eer',