Esempio n. 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)
    X, _ = load_svmlight_file(data_file, zero_based=True)
    expected = np.array([
        1.372033834457397461e+00, -2.448803186416625977e+00,
        8.579480648040771484e-01, 1.369985580444335938e+00,
        -7.058695554733276367e-01, 4.134958684444427490e-01,
        -2.247941017150878906e+00, -2.461995363235473633e+00,
        -2.394921064376831055e+00, -1.191793322563171387e+00,
        9.672126173973083496e-02, 2.687671184539794922e-01,
        1.417675256729125977e+00, -1.832636356353759766e+00,
        -5.582004785537719727e-02, -9.497703313827514648e-01,
        -1.219825387001037598e+00, 1.512521862983703613e+00,
        -1.179921030998229980e-01, -2.383430719375610352e+00,
        -9.094548225402832031e-01
    ])
    expected = expected.reshape((-1, 1))
    print('Testing inference on XGBoost LETOR...')
    assert np.allclose(model.run(_sparse_to_dense(X))[0], expected)


if __name__ == '__main__':
    arch = get_arch()
    model_names = [
        'xgboost-mnist-1.10.0', 'xgboost-iris-1.10.0', 'xgboost-letor-1.10.0'
    ]
    for model_name in model_names:
        get_models(model_name, arch, kind='treelite')
    test_mnist()
    test_iris()
    test_letor()
    print('All tests passed!')
def set_up():
    arch = get_arch()
    model_names = ['resnet18_v1', '4in2out', 'assign_op']
    for model_name in model_names:
        get_models(model_name, arch, kind='tvm')