def test_mlp_call(): new_base = mlp.MLP() x = tf.ones((1, 784)) y = new_base(x) assert y.shape == (1, 128)
def test_cross_entropy_fit(): (x, y), (_, _) = tf.keras.datasets.mnist.load_data() train = pair.BalancedPairDataset(x, y, n_pairs=10, input_shape=(x.shape[0], 784)) new_base = mlp.MLP() new_siamese = cross_entropy.CrossEntropySiamese(new_base) new_siamese.compile(optimizer=tf.optimizers.Adam(learning_rate=0.001)) new_siamese.fit(train.batches, epochs=1)
def test_triplet_evaluate(): (x, y), (_, _) = tf.keras.datasets.mnist.load_data() train = batch.BatchDataset(x[:10], y[:10], input_shape=(10, 784)) new_base = mlp.MLP() new_siamese = triplet.TripletSiamese(new_base) new_siamese.compile(optimizer=tf.optimizers.Adam(learning_rate=0.001)) new_siamese.fit(train.batches, epochs=1) new_siamese.evaluate(train.batches)
def test_triplet_step(): (x, y), (_, _) = tf.keras.datasets.mnist.load_data() new_base = mlp.MLP() new_siamese = triplet.TripletSiamese(new_base) new_siamese.compile(optimizer=tf.optimizers.Adam(learning_rate=0.001)) x = tf.ones((10, 784)) y = tf.zeros(10) new_siamese.step(x, y)
def test_cross_entropy_step(): (x, y), (_, _) = tf.keras.datasets.mnist.load_data() new_base = mlp.MLP() new_siamese = cross_entropy.CrossEntropySiamese(new_base) new_siamese.compile(optimizer=tf.optimizers.Adam(learning_rate=0.001)) x1 = tf.ones((1, 784)) x2 = tf.ones((1, 784)) y = tf.zeros(1) new_siamese.step(x1, x2, y)
def test_triplet_predict(): (x, y), (_, _) = tf.keras.datasets.mnist.load_data() train = batch.BatchDataset(x[:10], y[:10], input_shape=(10, 784)) new_base = mlp.MLP() new_siamese = triplet.TripletSiamese(new_base) new_siamese.compile(optimizer=tf.optimizers.Adam(learning_rate=0.001)) new_siamese.fit(train.batches, epochs=1) x1 = tf.ones((1, 784)) x2 = tf.ones((1, 784)) new_siamese.distance = "L1" new_siamese.predict(x1, x2) new_siamese.distance = "L2" new_siamese.predict(x1, x2) new_siamese.distance = "angular" new_siamese.predict(x1, x2)
def test_contrastive_predict(): (x, y), (_, _) = tf.keras.datasets.mnist.load_data() train = pair.BalancedPairDataset(x, y, n_pairs=10, input_shape=(x.shape[0], 784)) new_base = mlp.MLP() new_siamese = contrastive.ContrastiveSiamese(new_base) new_siamese.compile(optimizer=tf.optimizers.Adam(learning_rate=0.001)) new_siamese.fit(train.batches, epochs=1) x1 = tf.ones((1, 784)) x2 = tf.ones((1, 784)) new_siamese.distance = "L1" new_siamese.predict(x1, x2) new_siamese.distance = "L2" new_siamese.predict(x1, x2) new_siamese.distance = "angular" new_siamese.predict(x1, x2)
def test_mlp(): new_base = mlp.MLP() assert new_base.name == "mlp"