test.py 1.79 KB
Newer Older
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import bob.io.base
from bob.io.base.test_utils import datafile
import bob.ip.tensorflow_extractor
import tensorflow as tf

import pkg_resources
import numpy
numpy.random.seed(10)
import os

slim = tf.contrib.slim
from . import scratch_network


def test_output():

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
17 18 19
    # Loading MNIST model
    filename = os.path.join(pkg_resources.resource_filename(
        __name__, 'data'), 'model.ckp')
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
20 21 22 23 24
    inputs = tf.placeholder(tf.float32, shape=(None, 28, 28, 1))

    # Testing the last output
    graph = scratch_network(inputs)
    extractor = bob.ip.tensorflow_extractor.Extractor(filename, inputs, graph)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
25

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
26 27 28 29
    data = numpy.random.rand(2, 28, 28, 1).astype("float32")
    output = extractor(data)
    assert extractor(data).shape == (2, 10)
    del extractor
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
30

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
31 32 33 34
    # Testing flatten
    inputs = tf.placeholder(tf.float32, shape=(None, 28, 28, 1))
    graph = scratch_network(inputs, end_point="flatten1")
    extractor = bob.ip.tensorflow_extractor.Extractor(filename, inputs, graph)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
35

Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
36 37
    data = numpy.random.rand(2, 28, 28, 1).astype("float32")
    output = extractor(data)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
38
    assert output.shape == (2, 1690)
Tiago de Freitas Pereira's avatar
Tiago de Freitas Pereira committed
39 40
    del extractor

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
41 42 43 44 45 46 47 48

def test_facenet():
    from bob.ip.tensorflow_extractor import FaceNet
    extractor = FaceNet()
    data = numpy.random.rand(3, 160, 160).astype("uint8")
    output = extractor(data)
    assert output.size == 128, output.shape

49 50 51 52 53 54 55
def test_drgan():
    from bob.ip.tensorflow_extractor import DrGanMSUExtractor
    extractor = DrGanMSUExtractor()
    data = numpy.random.rand(3, 96, 96).astype("uint8")
    output = extractor(data)
    assert output.size == 320, output.shape

56 57 58 59 60 61 62
def test_vgg16():
    from bob.ip.tensorflow_extractor import VGGFace
    extractor = VGGFace()
    data = numpy.random.rand(3, 224, 224).astype("uint8")
    output = extractor(data)
    assert output.size == 4096, output.shape