################### # Create datasets # ################### train = LibriSpeechDataset(training_set, n_seconds) valid = LibriSpeechDataset(validation_set, n_seconds, stochastic=False) train_generator = (whiten_downsample(batch) for batch in train.yield_verification_batches(batchsize)) valid_generator = (whiten_downsample(batch) for batch in valid.yield_verification_batches(batchsize)) ################ # Define model # ################ encoder = get_baseline_convolutional_encoder(model_n_filters, model_embedding_dimension) siamese = build_siamese_net(encoder, (input_length, 1)) opt = Adam(clipnorm=1.) 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=[
pad=pad) batch_preprocessor = BatchPreProcessor('siamese', preprocess_instances(downsampling)) train_generator = (batch_preprocessor(batch) for batch in train.yield_verification_batches(batchsize)) valid_generator = (batch_preprocessor(batch) for batch in valid.yield_verification_batches(batchsize)) ################ # Define model # ################ encoder = get_baseline_convolutional_encoder(filters, embedding_dimension, dropout=dropout) siamese = build_siamese_net(encoder, (input_length, 1), 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,