Example #1
0
def test_mlp_call():
    new_base = mlp.MLP()

    x = tf.ones((1, 784))

    y = new_base(x)

    assert y.shape == (1, 128)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
def test_mlp():
    new_base = mlp.MLP()

    assert new_base.name == "mlp"