Esempio n. 1
0
def test_prediction(app, last_feature_dim):
    file = os.path.join(os.path.dirname(__file__), "fixtures", "elephant.jpg")
    img = keras.preprocessing.image.load_img(file)
    img = keras.preprocessing.image.img_to_array(img)
    img = lqz.preprocess_input(img)
    model = app(weights="imagenet")
    preds = model.predict(np.expand_dims(img, axis=0))

    # Test correct label is in top 3 (weak correctness test).
    names = [p[1] for p in lqz.decode_predictions(preds, top=3)[0]]
    assert "African_elephant" in names
Esempio n. 2
0
def preprocess(data):
    return lqz.preprocess_input(data["image"])
Esempio n. 3
0
def test_image(request):
    file = os.path.join(os.path.dirname(__file__), "fixtures", "elephant.jpg")
    img = keras.preprocessing.image.load_img(file)
    img = keras.preprocessing.image.img_to_array(img)
    img = lqz.preprocess_input(img)
    return np.expand_dims(img, axis=0)
Esempio n. 4
0
def preprocess(data):
    img = lqz.preprocess_input(data["image"])
    label = tf.one_hot(data["label"], 1000)
    return img, label 
Esempio n. 5
0
def test_numpy_input():
    image = np.random.randint(0, 255, size=(300, 300, 3), dtype="uint8")
    prepro = preprocess_input(image)
    assert isinstance(prepro, np.ndarray)
Esempio n. 6
0
def test_wrong_input():
    with pytest.raises(ValueError, match="Input must be of size .*"):
        preprocess_input(np.random.randint(0, 255, size=(4, 32, 32, 3), dtype="uint8"))
Esempio n. 7
0
def test_tensor_input():
    image = np.random.randint(0, 255, size=(300, 300, 3), dtype="uint8")
    tf_image = tf.constant(image)
    prepro = preprocess_input(tf_image)
    assert isinstance(prepro, tf.Tensor)