@@ -37,18 +37,19 @@ public virtual string TransformText()
37
37
//*****************************************************************************************
38
38
39
39
using System;
40
+ using System.IO;
40
41
using System.Linq;
41
42
using Microsoft.ML;
42
43
using " ) ;
43
44
44
- #line 17 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
45
+ #line 18 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
45
46
this . Write ( this . ToStringHelper . ToStringWithCulture ( Namespace ) ) ;
46
47
47
48
#line default
48
49
#line hidden
49
50
this . Write ( ".Model.DataModels;\r \n \r \n \r \n namespace " ) ;
50
51
51
- #line 20 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
52
+ #line 21 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
52
53
this . Write ( this . ToStringHelper . ToStringWithCulture ( Namespace ) ) ;
53
54
54
55
#line default
@@ -57,35 +58,35 @@ public virtual string TransformText()
57
58
"d and use for predictions\r \n private const string MODEL_FILEPATH = @\" MLMod" +
58
59
"el.zip\" ;\r \n \r \n //Dataset to use for predictions \r \n " ) ;
59
60
60
- #line 28 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
61
+ #line 29 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
61
62
if ( string . IsNullOrEmpty ( TestDataPath ) ) {
62
63
63
64
#line default
64
65
#line hidden
65
66
this . Write ( " private const string DATA_FILEPATH = @\" " ) ;
66
67
67
- #line 29 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
68
+ #line 30 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
68
69
this . Write ( this . ToStringHelper . ToStringWithCulture ( TrainDataPath ) ) ;
69
70
70
71
#line default
71
72
#line hidden
72
73
this . Write ( "\" ;\r \n " ) ;
73
74
74
- #line 30 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
75
+ #line 31 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
75
76
} else {
76
77
77
78
#line default
78
79
#line hidden
79
80
this . Write ( " private const string DATA_FILEPATH = @\" " ) ;
80
81
81
- #line 31 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
82
+ #line 32 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
82
83
this . Write ( this . ToStringHelper . ToStringWithCulture ( TestDataPath ) ) ;
83
84
84
85
#line default
85
86
#line hidden
86
87
this . Write ( "\" ;\r \n " ) ;
87
88
88
- #line 32 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
89
+ #line 33 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
89
90
}
90
91
91
92
#line default
@@ -98,7 +99,7 @@ static void Main(string[] args)
98
99
// Training code used by ML.NET CLI and AutoML to generate the model
99
100
//ModelBuilder.CreateModel();
100
101
101
- ITransformer mlModel = mlContext.Model.Load(MODEL_FILEPATH, out DataViewSchema inputSchema);
102
+ ITransformer mlModel = mlContext.Model.Load(GetAbsolutePath( MODEL_FILEPATH) , out DataViewSchema inputSchema);
102
103
var predEngine = mlContext.Model.CreatePredictionEngine<SampleObservation, SamplePrediction>(mlModel);
103
104
104
105
// Create sample data to do a single prediction with it
@@ -109,50 +110,50 @@ static void Main(string[] args)
109
110
110
111
" ) ;
111
112
112
- #line 50 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
113
+ #line 51 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
113
114
if ( "BinaryClassification" . Equals ( TaskType ) ) {
114
115
115
116
#line default
116
117
#line hidden
117
118
this . Write ( " Console.WriteLine($\" Single Prediction --> Actual value: {sampleData." ) ;
118
119
119
- #line 51 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
120
+ #line 52 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
120
121
this . Write ( this . ToStringHelper . ToStringWithCulture ( Utils . Normalize ( LabelName ) ) ) ;
121
122
122
123
#line default
123
124
#line hidden
124
125
this . Write ( "} | Predicted value: {predictionResult.Prediction}\" );\r \n " ) ;
125
126
126
- #line 52 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
127
+ #line 53 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
127
128
} else if ( "Regression" . Equals ( TaskType ) ) {
128
129
129
130
#line default
130
131
#line hidden
131
132
this . Write ( " Console.WriteLine($\" Single Prediction --> Actual value: {sampleData." ) ;
132
133
133
- #line 53 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
134
+ #line 54 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
134
135
this . Write ( this . ToStringHelper . ToStringWithCulture ( Utils . Normalize ( LabelName ) ) ) ;
135
136
136
137
#line default
137
138
#line hidden
138
139
this . Write ( "} | Predicted value: {predictionResult.Score}\" );\r \n " ) ;
139
140
140
- #line 54 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
141
+ #line 55 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
141
142
} else if ( "MulticlassClassification" . Equals ( TaskType ) ) {
142
143
143
144
#line default
144
145
#line hidden
145
146
this . Write ( " Console.WriteLine($\" Single Prediction --> Actual value: {sampleData." ) ;
146
147
147
- #line 55 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
148
+ #line 56 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
148
149
this . Write ( this . ToStringHelper . ToStringWithCulture ( Utils . Normalize ( LabelName ) ) ) ;
149
150
150
151
#line default
151
152
#line hidden
152
153
this . Write ( "} | Predicted value: {predictionResult.Prediction} | Predicted scores: [{String.J" +
153
154
"oin(\" ,\" , predictionResult.Score)}]\" );\r \n " ) ;
154
155
155
- #line 56 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
156
+ #line 57 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
156
157
}
157
158
158
159
#line default
@@ -171,28 +172,28 @@ private static SampleObservation CreateSingleDataSample(MLContext mlContext, str
171
172
path: dataFilePath,
172
173
hasHeader : " ) ;
173
174
174
- #line 69 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
175
+ #line 70 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
175
176
this . Write ( this . ToStringHelper . ToStringWithCulture ( HasHeader . ToString ( ) . ToLowerInvariant ( ) ) ) ;
176
177
177
178
#line default
178
179
#line hidden
179
180
this . Write ( ",\r \n separatorChar : \' " ) ;
180
181
181
- #line 70 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
182
+ #line 71 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
182
183
this . Write ( this . ToStringHelper . ToStringWithCulture ( Regex . Escape ( Separator . ToString ( ) ) ) ) ;
183
184
184
185
#line default
185
186
#line hidden
186
187
this . Write ( "\' ,\r \n allowQuoting : " ) ;
187
188
188
- #line 71 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
189
+ #line 72 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
189
190
this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowQuoting . ToString ( ) . ToLowerInvariant ( ) ) ) ;
190
191
191
192
#line default
192
193
#line hidden
193
194
this . Write ( ",\r \n allowSparse: " ) ;
194
195
195
- #line 72 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
196
+ #line 73 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
196
197
this . Write ( this . ToStringHelper . ToStringWithCulture ( AllowSparse . ToString ( ) . ToLowerInvariant ( ) ) ) ;
197
198
198
199
#line default
@@ -204,13 +205,23 @@ private static SampleObservation CreateSingleDataSample(MLContext mlContext, str
204
205
.First();
205
206
return sampleForPrediction;
206
207
}
208
+
209
+ public static string GetAbsolutePath(string relativePath)
210
+ {
211
+ FileInfo _dataRoot = new FileInfo(typeof(Program).Assembly.Location);
212
+ string assemblyFolderPath = _dataRoot.Directory.FullName;
213
+
214
+ string fullPath = Path.Combine(assemblyFolderPath, relativePath);
215
+
216
+ return fullPath;
217
+ }
207
218
}
208
219
}
209
220
" ) ;
210
221
return this . GenerationEnvironment . ToString ( ) ;
211
222
}
212
223
213
- #line 81 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
224
+ #line 92 "E:\src\machinelearning\src\mlnet\Templates\Console\PredictProgram.tt"
214
225
215
226
public string TaskType { get ; set ; }
216
227
public string Namespace { get ; set ; }
0 commit comments