@@ -2,57 +2,57 @@ module TestHighlevel
2
2
3
3
using Test
4
4
using ONNXRunTime
5
- const OX = ONNXRunTime
5
+ const ORT = ONNXRunTime
6
6
using ONNXRunTime: juliatype
7
7
8
8
@testset " high level" begin
9
9
@testset " increment2x3.onnx" begin
10
- path = OX . testdatapath (" increment2x3.onnx" )
11
- model = OX . load_inference (path, execution_provider= :cpu )
12
- @test OX . input_names (model) == [" input" ]
13
- @test OX . output_names (model) == [" output" ]
14
- @test OX . input_names (model) === model. input_names
15
- @test OX . output_names (model) === model. output_names
10
+ path = ORT . testdatapath (" increment2x3.onnx" )
11
+ model = ORT . load_inference (path, execution_provider= :cpu )
12
+ @test ORT . input_names (model) == [" input" ]
13
+ @test ORT . output_names (model) == [" output" ]
14
+ @test ORT . input_names (model) === model. input_names
15
+ @test ORT . output_names (model) === model. output_names
16
16
input = randn (Float32, 2 ,3 )
17
17
#= this works =# model (Dict (" input" => randn (Float32, 2 ,3 )), [" output" ])
18
- @test_throws OX . ArgumentError model (Dict (" nonsense" => input), [" output" ])
19
- @test_throws OX . ArgumentError model (Dict (" input" => input), [" nonsense" ])
20
- @test_throws OX . OrtException model (Dict (" input" => input), String[])
21
- @test_throws OX . ArgumentError model (Dict (" input" => input, " unused" => input), [" output" ])
22
- @test_throws OX . ArgumentError model (Dict (" input" => input, " unused" => input), [" output" ])
23
- @test_throws OX . OrtException model (Dict (" input" => randn (Float32, 3 ,2 )), [" output" ])
18
+ @test_throws ORT . ArgumentError model (Dict (" nonsense" => input), [" output" ])
19
+ @test_throws ORT . ArgumentError model (Dict (" input" => input), [" nonsense" ])
20
+ @test_throws ORT . OrtException model (Dict (" input" => input), String[])
21
+ @test_throws ORT . ArgumentError model (Dict (" input" => input, " unused" => input), [" output" ])
22
+ @test_throws ORT . ArgumentError model (Dict (" input" => input, " unused" => input), [" output" ])
23
+ @test_throws ORT . OrtException model (Dict (" input" => randn (Float32, 3 ,2 )), [" output" ])
24
24
@test_throws Exception model (Dict (" input" => randn (Int, 2 ,3 ) ), [" output" ])
25
- @test_throws OX . OrtException model (Dict (" input" => randn (Float64, 2 ,3 )), [" output" ])
25
+ @test_throws ORT . OrtException model (Dict (" input" => randn (Float64, 2 ,3 )), [" output" ])
26
26
y = model (Dict (" input" => input), [" output" ])
27
27
@test y == Dict (" output" => input .+ 1f0 )
28
28
y = model (Dict (" input" => input))
29
29
@test y == Dict (" output" => input .+ 1f0 )
30
30
end
31
31
@testset " adder1x2x3.onnx" begin
32
- path = OX . testdatapath (" adder1x2x3.onnx" )
33
- model = OX . load_inference (path)
34
- @test OX . input_names (model) == [" x" , " y" ]
35
- @test OX . output_names (model) == [" sum" ]
32
+ path = ORT . testdatapath (" adder1x2x3.onnx" )
33
+ model = ORT . load_inference (path)
34
+ @test ORT . input_names (model) == [" x" , " y" ]
35
+ @test ORT . output_names (model) == [" sum" ]
36
36
x = randn (Float32, 1 ,2 ,3 )
37
37
y = randn (Float32, 1 ,2 ,3 )
38
38
d = model (Dict (" x" => x, " y" => y))
39
39
@test d isa AbstractDict
40
40
@test d == Dict (" sum" => x+ y)
41
41
end
42
42
@testset " diagonal1x2x3x4.onnx" begin
43
- path = OX . testdatapath (" diagonal1x2x3x4.onnx" )
44
- model = OX . load_inference (path)
45
- @test OX . input_names (model) == [" in" ]
46
- @test OX . output_names (model) == [" out1" , " out2" ]
43
+ path = ORT . testdatapath (" diagonal1x2x3x4.onnx" )
44
+ model = ORT . load_inference (path)
45
+ @test ORT . input_names (model) == [" in" ]
46
+ @test ORT . output_names (model) == [" out1" , " out2" ]
47
47
x = randn (Float64, 1 ,2 ,3 ,4 )
48
48
d = model (Dict (" in" => x))
49
49
@test d == Dict (" out1" => x, " out2" => x)
50
50
end
51
51
@testset " swap_x_.onnx" begin
52
- path = OX . testdatapath (" swap_x_.onnx" )
53
- model = OX . load_inference (path)
54
- @test OX . input_names (model) == [" in1" , " in2" ]
55
- @test OX . output_names (model) == [" out1" , " out2" ]
52
+ path = ORT . testdatapath (" swap_x_.onnx" )
53
+ model = ORT . load_inference (path)
54
+ @test ORT . input_names (model) == [" in1" , " in2" ]
55
+ @test ORT . output_names (model) == [" out1" , " out2" ]
56
56
in1 = randn (Float32, 2 ,3 )
57
57
in2 = randn (Float32, 4 ,5 )
58
58
res = model ((;in1, in2))
@@ -68,22 +68,22 @@ using ONNXRunTime: juliatype
68
68
@test occursin (" out2" , s)
69
69
end
70
70
@testset " getindex_12.onnx" begin
71
- path = OX . testdatapath (" getindex_12.onnx" )
72
- model = OX . load_inference (path)
71
+ path = ORT . testdatapath (" getindex_12.onnx" )
72
+ model = ORT . load_inference (path)
73
73
inputs = (input= collect (reshape (1f0 : 20 , 4 ,5 )),)
74
74
out = model (inputs). output
75
75
@test inputs. input[2 ,3 ] == only (out)
76
76
end
77
77
@testset " copy2d.onnx" begin
78
- path = OX . testdatapath (" copy2d.onnx" )
79
- model = OX . load_inference (path)
78
+ path = ORT . testdatapath (" copy2d.onnx" )
79
+ model = ORT . load_inference (path)
80
80
inputs = (input= randn (Float32,3 ,4 ),)
81
81
out = model (inputs). output
82
82
@test inputs. input == out
83
83
end
84
84
@testset " matmul.onnx" begin
85
- path = OX . testdatapath (" matmul.onnx" )
86
- model = OX . load_inference (path)
85
+ path = ORT . testdatapath (" matmul.onnx" )
86
+ model = ORT . load_inference (path)
87
87
inputs = (
88
88
input1 = randn (Float32, 2 ,3 ),
89
89
input2 = randn (Float32, 3 ,4 ),
@@ -92,8 +92,8 @@ using ONNXRunTime: juliatype
92
92
@test out ≈ inputs. input1 * inputs. input2
93
93
end
94
94
@testset " xyz_3x4x5.onnx" begin
95
- path = OX . testdatapath (" xyz_3x4x5.onnx" )
96
- model = OX . load_inference (path)
95
+ path = ORT . testdatapath (" xyz_3x4x5.onnx" )
96
+ model = ORT . load_inference (path)
97
97
inputs = (input= randn (Float32,4 ,10 ),)
98
98
out = model (inputs)
99
99
@test out. identity == inputs. input
@@ -108,17 +108,17 @@ using ONNXRunTime: juliatype
108
108
end
109
109
end
110
110
@testset " Conv1d1.onnx" begin
111
- path = OX . testdatapath (" Conv1d1.onnx" )
112
- model = OX . load_inference (path)
111
+ path = ORT . testdatapath (" Conv1d1.onnx" )
112
+ model = ORT . load_inference (path)
113
113
inputs = (input= randn (Float32,4 ,2 ,10 ),)
114
114
out = model (inputs)
115
115
expected = fill (0f0 , 4 ,3 ,8 )
116
116
expected[:,2 ,:] .= 1
117
117
@test out. output == expected
118
118
end
119
119
@testset " Conv1d2.onnx" begin
120
- path = OX . testdatapath (" Conv1d2.onnx" )
121
- model = OX . load_inference (path)
120
+ path = ORT . testdatapath (" Conv1d2.onnx" )
121
+ model = ORT . load_inference (path)
122
122
input = Array {Float32,3} (undef, (1 ,2 ,3 ))
123
123
input[1 ,1 ,1 ] = 1
124
124
input[1 ,1 ,2 ] = 2
@@ -136,10 +136,10 @@ using ONNXRunTime: juliatype
136
136
@test out[1 ,2 ,3 ] == 0
137
137
end
138
138
@testset " Dict2Dict.onnx" begin
139
- path = OX . testdatapath (" Dict2Dict.onnx" )
140
- model = OX . load_inference (path, execution_provider= :cpu )
141
- @test OX . input_names (model) == [" x" , " y" ]
142
- @test OX . output_names (model) == [" x_times_y" , " x_plus_y" , " x_minus_y" , " x_plus_1" , " y_plus_2" ]
139
+ path = ORT . testdatapath (" Dict2Dict.onnx" )
140
+ model = ORT . load_inference (path, execution_provider= :cpu )
141
+ @test ORT . input_names (model) == [" x" , " y" ]
142
+ @test ORT . output_names (model) == [" x_times_y" , " x_plus_y" , " x_minus_y" , " x_plus_1" , " y_plus_2" ]
143
143
nb = rand (1 : 10 )
144
144
x = randn (Float32, nb,3 )
145
145
y = randn (Float32, nb,3 )
0 commit comments