Esempio n. 1
0
def test_classification_basics(net, shape, weights, outputs, middles):
    with tf.Graph().as_default():
        inputs = tf.placeholder(tf.float32, [None] + list(shape))
        model = net(inputs, is_training=False)
        assert isinstance(model, tf.Tensor)

        x = np.random.random((1, ) + shape).astype(np.float32) * 255

        with tf.Session() as sess:
            nets.init(model)
            y = model.eval({inputs: model.preprocess(x)})

        assert y.shape == (1, 1000)

        # Check whether the tensor names match the desired ones
        assert 'probs' in model.name  # for `model`
        assert 'logits' in model.logits.name  # for `model.logits`
        model_name = model.aliases[0]
        for (a, b) in zip(model.get_middles(), middle_names(model_name)[1]):
            assert a.name.endswith(b)  # for `model.get_middles()`

        # Disable the following tests for TF==1.1.0
        if LooseVersion(tf.__version__) == LooseVersion('1.1.0'):
            return

        # Check whether the desired list is returned
        assert len(model.get_weights()) == weights
        assert len(model.get_outputs()) == outputs
        assert len(model.get_middles()) == middles

        tf.reset_default_graph()

    # Clear GraphDef to avoid `GraphDef cannot be larger than 2GB`
    with tf.Graph().as_default():
        inputs = tf.placeholder(tf.float32, [None] + list(shape))

        # Check whether the desired list is returned under scope functions
        with tf.name_scope('a'):
            with tf.variable_scope('b'):
                with tf.name_scope('c'):
                    model = net(inputs, is_training=False)
                    assert len(model.get_weights()) == weights
                    assert len(model.get_outputs()) == outputs
                    assert len(model.get_middles()) == middles

        with tf.variable_scope('d'):
            with tf.name_scope('e'):
                with tf.variable_scope('f'):
                    model = net(inputs, is_training=False)
                    assert len(model.get_weights()) == weights
                    assert len(model.get_outputs()) == outputs
                    assert len(model.get_middles()) == middles

        tf.reset_default_graph()
Esempio n. 2
0
def test_basics(net, shape):
    inputs = tf.placeholder(tf.float32, [None] + list(shape))
    model = net(inputs, is_training=False)
    assert isinstance(model, tf.Tensor)

    x = np.random.random((1, ) + shape).astype(np.float32)

    with tf.Session() as sess:
        nets.init(model)
        y = model.eval({inputs: x})

    assert y.shape == (1, 1000)
Esempio n. 3
0
def test_detection_basics(net, shape, stem):
    # TODO: Once the roi-pooling dependency is removed,
    # FasterRCNN-related tests should be added.
    with tf.Graph().as_default():
        inputs = tf.placeholder(tf.float32, [None] + list(shape))
        model = net(inputs, stem, is_training=False)
        assert isinstance(model, tf.Tensor)

        x = np.random.random((1, 733, 490, 3)).astype(np.float32) * 255

        with tf.Session() as sess:
            nets.init(model)
            y = model.eval({inputs: model.preprocess(x)})
Esempio n. 4
0
def test_basics(net, shape):
    inputs = tf.placeholder(tf.float32, [None] + list(shape))
    model = net(inputs, is_training=False)
    assert isinstance(model, tf.Tensor)

    x = np.random.random((1,) + shape).astype(np.float32)

    with tf.Session() as sess:
        nets.init(model)
        y = model.eval({inputs: x})

    for (a, b) in zip(model.get_middles(), direct(model.aliases[0])[1]):
        assert a.name.endswith(b)

    assert y.shape == (1, 1000)
Esempio n. 5
0
def test_detection_basics():
    # TODO: Once the roi-pooling dependency is removed,
    # FasterRCNN-related tests should be added.
    inputs = tf.placeholder(tf.float32, [None, 416, 416, 3])
    model1 = nets.YOLOv2(inputs, nets.Darknet19, is_training=False)
    assert isinstance(model1, tf.Tensor)

    model2 = nets.TinyYOLOv2(inputs, nets.TinyDarknet19, is_training=False)
    assert isinstance(model2, tf.Tensor)

    x = np.random.random((1, 733, 490, 3)).astype(np.float32) * 255

    with tf.Session() as sess:
        nets.init([model1, model2])
        y1 = model1.eval({inputs: model1.preprocess(x)})
        y2 = model2.eval({inputs: model2.preprocess(x)})
Esempio n. 6
0
def test_classification_basics(net, shape, weights, outputs, middles):
    with tf.Graph().as_default():
        inputs = tf.placeholder(tf.float32, [None] + list(shape))
        model = net(inputs, is_training=False)
        assert isinstance(model, tf.Tensor)

        # Disable tests whether the desired list is returned for TF==1.1.0
        if LooseVersion(tf.__version__) > LooseVersion('1.1.0'):
            assert len(model.get_weights()) == weights
            assert len(model.get_outputs()) == outputs
            assert len(model.get_middles()) == middles

        x = np.random.random((1, ) + shape).astype(np.float32) * 255

        with tf.Session() as sess:
            nets.init(model)
            y = model.eval({inputs: model.preprocess(x)})

        # The tensor name of `model` should be `probs`.
        assert 'probs' in model.name

        # The tensor name of `model.logits` should be `logits`.
        assert 'logits' in model.logits.name

        # The tensor names from `get_middles()` should be the desired ones.
        for (a, b) in zip(model.get_middles(), direct(model.aliases[0])[1]):
            assert a.name.endswith(b)

        # Disable tests whether the desired list is returned for TF==1.1.0
        if LooseVersion(tf.__version__) > LooseVersion('1.1.0'):
            with tf.name_scope('a'):
                with tf.variable_scope('b'):
                    with tf.name_scope('c'):
                        model = net(inputs, is_training=False)
                        assert len(model.get_weights()) == weights
                        assert len(model.get_outputs()) == outputs
                        assert len(model.get_middles()) == middles

            with tf.variable_scope('d'):
                with tf.name_scope('e'):
                    with tf.variable_scope('f'):
                        model = net(inputs, is_training=False)
                        assert len(model.get_weights()) == weights
                        assert len(model.get_outputs()) == outputs
                        assert len(model.get_middles()) == middles

        assert y.shape == (1, 1000)