def test_tl_sequential(self): # Base model. base_model = models.Sequential() base_model.add(layers.Dense(20, activation="relu", input_shape=(100,))) # Triplet loss. tl = ngdlmodels.TL(base=base_model) self.assert_load_save_fine(tl)
def test_tl_functional(self): # Base model. base_model_input = layers.Input(shape=(100,)) base_model_output = base_model_input base_model_output = layers.Dense(20, activation="relu")(base_model_output) base = models.Model(base_model_input, base_model_output) # Triplet loss. tl = ngdlmodels.TL(base) self.assert_load_save_fine(tl)
# Triplet loss. latent_dim = 8 # Create the base-model. base_input = layers.Input(shape=(28, 28)) base_output = base_input base_output = layers.Flatten()(base_output) base_output = layers.Dense(512, activation="relu")(base_output) base_output = layers.Dense(256, activation="relu")(base_output) base_output = layers.Dense(128, activation="relu")(base_output) base_output = layers.Dense(latent_dim)(base_output) base = models.Model(base_input, base_output) # Create the triplet loss model. tl = ngdlmodels.TL(base) tl.compile(optimizer="rmsprop", triplet_loss="euclidean") tl.summary() # Train. print("Train...") history = tl.fit( x_input_train, y_output_train, epochs=100, batch_size=128, steps_per_epoch=1000, minibatch_size=10, shuffle=True, validation_data=(x_input_validate, y_output_validate), validation_steps=500 )