Пример #1
0
def test_get_set_input():
    model_path = get_models(model_name='4in2out', arch=get_arch(), kind='tvm')
    device = 'cpu'
    model = DLRModel(model_path, device)

    input1 = np.asarray([1., 2.])
    input2 = np.asarray([3., 4.])
    input3 = np.asarray([5., 6., 7])
    input4 = np.asarray([8., 9., 10])
    
    model.run({'data1': input1, 'data2': input2, 'data3': input3, 'data4': input4})

    assert np.array_equal(model.get_input('data1'), input1)
    assert np.array_equal(model.get_input('data2'), input2)
    assert np.array_equal(model.get_input('data3'), input3)
    assert np.array_equal(model.get_input('data4'), input4)
Пример #2
0
def test_assign_op():
    model_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'assign_op')
    device = 'cpu'
    model = DLRModel(model_path, device)

    print('Testing _assign() operator...')
    # Example from https://github.com/dmlc/tvm/blob/bb87f044099ba61ba4782d17dd9127b869936373/nnvm/tests/python/compiler/test_top_assign.py
    np.random.seed(seed=0)
    input1 = np.random.random(size=(5, 3, 18, 18))
    model.run({'w': input1})
    input1_next = model.get_input('w2', shape=(5, 3, 18, 18))
    assert np.allclose(input1_next, input1 + 2)

    model.run({})
    input1_next = model.get_input('w2', shape=(5, 3, 18, 18))
    assert np.allclose(input1_next, input1 + 3)
def test_mobilenet_v1_0_75_224_quant():
    # Load the model
    model_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'mobilenet_v1_0.75_224_quant')
    device = 'cpu'
    model = DLRModel(model_path, device)
    # load image (dtype: uint8)
    image = np.load(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     'cat_224_uint8.npy'))
    print('Testing inference on mobilenet_v1_0.75_224_quant...')
    probabilities = model.run({'input': image})
    assert probabilities[0].argmax() == 282
    assert model.get_input_names() == ["input"]
    assert model.get_input_dtypes() == ["uint8"]
    assert model.get_output_dtypes() == ["uint8"]
    assert model.get_input_dtype(0) == "uint8"
    assert model.get_output_dtype(0) == "uint8"
    input2 = model.get_input("input")
    assert input2.dtype == 'uint8'
    assert input2.shape == (1, 224, 224, 3)
    assert (input2 == image).all()
Пример #4
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)
Пример #5
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)