3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
+ using System . Collections . Generic ;
6
7
using Microsoft . ML . Data ;
7
8
using Microsoft . ML . Transforms ;
8
9
using Microsoft . ML . Transforms . Onnx ;
@@ -36,6 +37,34 @@ public static OnnxScoringEstimator ApplyOnnxModel(this TransformsCatalog catalog
36
37
bool fallbackToCpu = false )
37
38
=> new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , modelFile , gpuDeviceId , fallbackToCpu ) ;
38
39
40
+ /// <summary>
41
+ /// Create a <see cref="OnnxScoringEstimator"/>, which applies a pre-trained Onnx model to the input column.
42
+ /// Input/output columns are determined based on the input/output columns of the provided ONNX model.
43
+ /// </summary>
44
+ /// <remarks>
45
+ /// The name/type of input columns must exactly match name/type of the ONNX model inputs.
46
+ /// The name/type of the produced output columns will match name/type of the ONNX model outputs.
47
+ /// </remarks>
48
+ /// <param name="catalog">The transform's catalog.</param>
49
+ /// <param name="modelFile">The path of the file containing the ONNX model.</param>
50
+ /// <param name="shapeDictionary">ONNX shape should be used to over those loaded from <paramref name="modelFile"/>.</param>
51
+ /// <param name="gpuDeviceId">Optional GPU device ID to run execution on, <see langword="null" /> to run on CPU.</param>
52
+ /// <param name="fallbackToCpu">If GPU error, raise exception or fallback to CPU.</param>
53
+ /// <example>
54
+ /// <format type="text/markdown">
55
+ /// <]
57
+ /// ]]>
58
+ /// </format>
59
+ /// </example>
60
+ public static OnnxScoringEstimator ApplyOnnxModel ( this TransformsCatalog catalog ,
61
+ string modelFile ,
62
+ IDictionary < string , int [ ] > shapeDictionary ,
63
+ int ? gpuDeviceId = null ,
64
+ bool fallbackToCpu = false )
65
+ => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , modelFile , gpuDeviceId , fallbackToCpu ,
66
+ shapeDictionary : shapeDictionary ) ;
67
+
39
68
/// <summary>
40
69
/// Create a <see cref="OnnxScoringEstimator"/>, which applies a pre-trained Onnx model to the <paramref name="inputColumnName"/> column.
41
70
/// </summary>
@@ -58,7 +87,53 @@ public static OnnxScoringEstimator ApplyOnnxModel(this TransformsCatalog catalog
58
87
string modelFile ,
59
88
int ? gpuDeviceId = null ,
60
89
bool fallbackToCpu = false )
61
- => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , new [ ] { outputColumnName } , new [ ] { inputColumnName } , modelFile , gpuDeviceId , fallbackToCpu ) ;
90
+ => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , new [ ] { outputColumnName } , new [ ] { inputColumnName } ,
91
+ modelFile , gpuDeviceId , fallbackToCpu ) ;
92
+
93
+ /// <summary>
94
+ /// Create a <see cref="OnnxScoringEstimator"/>, which applies a pre-trained Onnx model to the <paramref name="inputColumnName"/> column.
95
+ /// </summary>
96
+ /// <param name="catalog">The transform's catalog.</param>
97
+ /// <param name="outputColumnName">The output column resulting from the transformation.</param>
98
+ /// <param name="inputColumnName">The input column.</param>
99
+ /// <param name="modelFile">The path of the file containing the ONNX model.</param>
100
+ /// <param name="shapeDictionary">ONNX shape should be used to over those loaded from <paramref name="modelFile"/>.</param>
101
+ /// <param name="gpuDeviceId">Optional GPU device ID to run execution on, <see langword="null" /> to run on CPU.</param>
102
+ /// <param name="fallbackToCpu">If GPU error, raise exception or fallback to CPU.</param>
103
+ /// <example>
104
+ /// <format type="text/markdown">
105
+ /// <]
107
+ /// ]]>
108
+ /// </format>
109
+ /// </example>
110
+ public static OnnxScoringEstimator ApplyOnnxModel ( this TransformsCatalog catalog ,
111
+ string outputColumnName ,
112
+ string inputColumnName ,
113
+ string modelFile ,
114
+ IDictionary < string , int [ ] > shapeDictionary ,
115
+ int ? gpuDeviceId = null ,
116
+ bool fallbackToCpu = false )
117
+ => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , new [ ] { outputColumnName } , new [ ] { inputColumnName } ,
118
+ modelFile , gpuDeviceId , fallbackToCpu , shapeDictionary : shapeDictionary ) ;
119
+
120
+ /// <summary>
121
+ /// Create a <see cref="OnnxScoringEstimator"/>, which applies a pre-trained Onnx model to the <paramref name="inputColumnNames"/> columns.
122
+ /// </summary>
123
+ /// <param name="catalog">The transform's catalog.</param>
124
+ /// <param name="outputColumnNames">The output columns resulting from the transformation.</param>
125
+ /// <param name="inputColumnNames">The input columns.</param>
126
+ /// <param name="modelFile">The path of the file containing the ONNX model.</param>
127
+ /// <param name="gpuDeviceId">Optional GPU device ID to run execution on, <see langword="null" /> to run on CPU.</param>
128
+ /// <param name="fallbackToCpu">If GPU error, raise exception or fallback to CPU.</param>
129
+ public static OnnxScoringEstimator ApplyOnnxModel ( this TransformsCatalog catalog ,
130
+ string [ ] outputColumnNames ,
131
+ string [ ] inputColumnNames ,
132
+ string modelFile ,
133
+ int ? gpuDeviceId = null ,
134
+ bool fallbackToCpu = false )
135
+ => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , outputColumnNames , inputColumnNames ,
136
+ modelFile , gpuDeviceId , fallbackToCpu ) ;
62
137
63
138
/// <summary>
64
139
/// Create a <see cref="OnnxScoringEstimator"/>, which applies a pre-trained Onnx model to the <paramref name="inputColumnNames"/> columns.
@@ -67,15 +142,18 @@ public static OnnxScoringEstimator ApplyOnnxModel(this TransformsCatalog catalog
67
142
/// <param name="outputColumnNames">The output columns resulting from the transformation.</param>
68
143
/// <param name="inputColumnNames">The input columns.</param>
69
144
/// <param name="modelFile">The path of the file containing the ONNX model.</param>
145
+ /// <param name="shapeDictionary">ONNX shape should be used to over those loaded from <paramref name="modelFile"/>.</param>
70
146
/// <param name="gpuDeviceId">Optional GPU device ID to run execution on, <see langword="null" /> to run on CPU.</param>
71
147
/// <param name="fallbackToCpu">If GPU error, raise exception or fallback to CPU.</param>
72
148
public static OnnxScoringEstimator ApplyOnnxModel ( this TransformsCatalog catalog ,
73
149
string [ ] outputColumnNames ,
74
150
string [ ] inputColumnNames ,
75
151
string modelFile ,
152
+ IDictionary < string , int [ ] > shapeDictionary ,
76
153
int ? gpuDeviceId = null ,
77
154
bool fallbackToCpu = false )
78
- => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , outputColumnNames , inputColumnNames , modelFile , gpuDeviceId , fallbackToCpu ) ;
155
+ => new OnnxScoringEstimator ( CatalogUtils . GetEnvironment ( catalog ) , outputColumnNames , inputColumnNames ,
156
+ modelFile , gpuDeviceId , fallbackToCpu , shapeDictionary : shapeDictionary ) ;
79
157
80
158
/// <summary>
81
159
/// Create <see cref="DnnImageFeaturizerEstimator"/>, which applies one of the pre-trained DNN models in
0 commit comments