Ejemplo n.º 1
0
def test_ssd_mobilenet_v2_model():
    model = DLRModel(MODEL_PATH.as_posix())
    data = np.load(DATA_PATH)
    assert model.get_input_names() == ['image_tensor']
    assert model.get_output_names() == [
        'detection_scores:0', 'detection_classes:0', 'num_detections:0'
    ]
    assert model.get_input_dtypes() == ['uint8']
    assert model.get_output_dtypes() == ['float32', 'float32', 'float32']
    outputs = model.run({"image_tensor": data})
    assert outputs[0].shape == (1, 100, 4)
    assert outputs[1].shape == (1, 100)
    assert outputs[2].shape == (1, 100)
    detections = np.multiply(np.ceil(outputs[1]), outputs[2])
    expected = np.zeros(detections.shape)
    expected[:, :6] = np.array([[1., 1., 1., 2., 3., 1]])
    comparison = detections == expected
    assert comparison.all()
def test_ssd_mobilenet_v2_model():
    model = DLRModel(MODEL_PATH.as_posix())
    data = np.load(DATA_PATH)
    assert model.get_input_names() == ['image_tensor']
    assert model.get_output_names() == [
        'detection_classes:0', 'num_detections:0', 'detection_boxes:0',
        'detection_scores:0'
    ]
    assert model.get_input_dtypes() == ['uint8']
    assert model.get_output_dtypes() == [
        'float32', 'float32', 'float32', 'float32'
    ]
    outputs = model.run({"image_tensor": data})
    assert outputs[0].shape == (1, 100)
    assert outputs[1].shape == (1, )
    assert outputs[2].shape == (1, 100, 4)
    assert outputs[3].shape == (1, 100)
    detections = np.multiply(np.ceil(outputs[3]), outputs[0])
    expected = np.zeros(detections.shape)
    assert np.count_nonzero(detections) == outputs[1][0]
Ejemplo n.º 3
0
def test_tf_model(dev_type=None, dev_id=None):
    _generate_frozen_graph()
    model = DLRModel(FROZEN_GRAPH_PATH, dev_type, dev_id)
    inp_names = model.get_input_names()
    assert inp_names == ['import/input1:0', 'import/input2:0']

    out_names = model.get_output_names()
    assert out_names == [
        'import/preproc/output1:0', 'import/preproc/output2:0'
    ]

    inp1 = [[4., 1.], [3., 2.]]
    inp2 = [[0., 1.], [1., 0.]]

    res = model.run({'import/input1:0': inp1, 'import/input2:0': inp2})
    assert res is not None
    assert len(res) == 2
    assert np.alltrue(res[0] == [[36., 361.], [49., 324.]])
    assert res[1] == 1

    m_inp1 = model.get_input('import/input1:0')
    m_inp2 = model.get_input('import/input2:0')
    assert np.alltrue(m_inp1 == inp1)
    assert np.alltrue(m_inp2 == inp2)
Ejemplo n.º 4
0
def test_tflite_model():
    _generate_tflite_file()

    m = DLRModel(TFLITE_FILE_PATH)
    inp_names = m.get_input_names()
    assert sorted(inp_names) == ['input1', 'input2']

    out_names = m.get_output_names()
    assert sorted(out_names) == ['preproc/output1', 'preproc/output2']

    inp1 = np.array([[4., 1.], [3., 2.]]).astype("float32")
    inp2 = np.array([[0., 1.], [1., 0.]]).astype("float32")

    res = m.run({'input1': inp1, 'input2': inp2})
    assert res is not None
    assert len(res) == 2
    exp_out0 = np.array([[36., 361.], [49., 324.]]).astype("float32")
    assert np.alltrue(res[0] == exp_out0)
    assert res[1] == 1

    m_inp1 = m.get_input('input1')
    m_inp2 = m.get_input('input2')
    assert np.alltrue(m_inp1 == inp1)
    assert np.alltrue(m_inp2 == inp2)