Skip to content

Commit 9de92e6

Browse files
authored
Fix model path in generated file (dotnet#230)
* removed console read key * fix model path * fix test
1 parent 9f8de06 commit 9de92e6

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/mlnet.Test/ApprovalTests/ConsoleCodeGeneratorTests.GeneratedTrainCodeTest.approved.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace MyNamespace
1616
{
1717
private static string TrainDataPath = @"x:\dummypath\dummy_train.csv";
1818
private static string TestDataPath = @"x:\dummypath\dummy_test.csv";
19-
private static string ModelPath = @"./model.zip";
19+
private static string ModelPath = @"..\..\..\model.zip";
2020

2121
// Set this flag to enable the training process.
2222
private static bool EnableTraining = false;

src/mlnet/Templates/Console/MLCodeGen.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ public virtual string TransformText()
4141
this.Write(this.ToStringHelper.ToStringWithCulture(TestPath));
4242
this.Write("\";\r\n");
4343
}
44-
this.Write(" private static string ModelPath = @\"./model.zip\";\r\n\r\n // Set this " +
45-
"flag to enable the training process.\r\n private static bool EnableTraining" +
46-
" = false;\r\n\r\n static void Main(string[] args)\r\n {\r\n // " +
47-
"Create MLContext to be shared across the model creation workflow objects \r\n " +
48-
" // Set a random seed for repeatable/deterministic results across multiple" +
49-
" trainings.\r\n var mlContext = new MLContext(seed: 1);\r\n\r\n " +
50-
"if (EnableTraining)\r\n {\r\n // Create, Train, Evaluate a" +
51-
"nd Save a model\r\n BuildTrainEvaluateAndSaveModel(mlContext);\r\n " +
52-
" ConsoleHelper.ConsoleWriteHeader(\"=============== End of training p" +
53-
"rocess ===============\");\r\n }\r\n else\r\n {\r\n " +
54-
" ConsoleHelper.ConsoleWriteHeader(\"Skipping the training process. Plea" +
55-
"se set the flag : \'EnableTraining\' to \'true\' to enable the training process.\");\r" +
56-
"\n }\r\n\r\n // Make a single test prediction loading the model" +
57-
" from .ZIP file\r\n TestSinglePrediction(mlContext);\r\n\r\n Con" +
58-
"soleHelper.ConsoleWriteHeader(\"=============== End of process, hit any key to fi" +
59-
"nish ===============\");\r\n Console.ReadKey();\r\n\r\n }\r\n\r\n " +
60-
"private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)\r" +
61-
"\n {\r\n // Data loading\r\n IDataView trainingDataView " +
62-
"= mlContext.Data.ReadFromTextFile<SampleObservation>(\r\n " +
63-
" path: TrainDataPath,\r\n " +
64-
" hasHeader : ");
44+
this.Write(" private static string ModelPath = @\"..\\..\\..\\model.zip\";\r\n\r\n // Se" +
45+
"t this flag to enable the training process.\r\n private static bool EnableT" +
46+
"raining = false;\r\n\r\n static void Main(string[] args)\r\n {\r\n " +
47+
" // Create MLContext to be shared across the model creation workflow objects " +
48+
"\r\n // Set a random seed for repeatable/deterministic results across m" +
49+
"ultiple trainings.\r\n var mlContext = new MLContext(seed: 1);\r\n\r\n " +
50+
" if (EnableTraining)\r\n {\r\n // Create, Train, Eva" +
51+
"luate and Save a model\r\n BuildTrainEvaluateAndSaveModel(mlContext" +
52+
");\r\n ConsoleHelper.ConsoleWriteHeader(\"=============== End of tra" +
53+
"ining process ===============\");\r\n }\r\n else\r\n {" +
54+
"\r\n ConsoleHelper.ConsoleWriteHeader(\"Skipping the training proces" +
55+
"s. Please set the flag : \'EnableTraining\' to \'true\' to enable the training proce" +
56+
"ss.\");\r\n }\r\n\r\n // Make a single test prediction loading th" +
57+
"e model from .ZIP file\r\n TestSinglePrediction(mlContext);\r\n\r\n " +
58+
" ConsoleHelper.ConsoleWriteHeader(\"=============== End of process, hit any ke" +
59+
"y to finish ===============\");\r\n Console.ReadKey();\r\n\r\n }\r\n\r\n " +
60+
" private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlCo" +
61+
"ntext)\r\n {\r\n // Data loading\r\n IDataView trainingDa" +
62+
"taView = mlContext.Data.ReadFromTextFile<SampleObservation>(\r\n " +
63+
" path: TrainDataPath,\r\n " +
64+
" hasHeader : ");
6565
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
6666
this.Write(",\r\n separatorChar : \'");
6767
this.Write(this.ToStringHelper.ToStringWithCulture(Regex.Escape(Separator.ToString())));

src/mlnet/Templates/Console/MLCodeGen.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace <#= Namespace #>
2424
<#if(!string.IsNullOrEmpty(TestPath)){ #>
2525
private static string TestDataPath = @"<#= TestPath #>";
2626
<# } #>
27-
private static string ModelPath = @"./model.zip";
27+
private static string ModelPath = @"..\..\..\model.zip";
2828

2929
// Set this flag to enable the training process.
3030
private static bool EnableTraining = false;

0 commit comments

Comments
 (0)