Skip to content

Commit

Permalink
Fix model path in generated file (dotnet#230)
Browse files Browse the repository at this point in the history
* removed console read key

* fix model path

* fix test
  • Loading branch information
srsaggam authored Feb 26, 2019
1 parent 9f8de06 commit 9de92e6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace MyNamespace
{
private static string TrainDataPath = @"x:\dummypath\dummy_train.csv";
private static string TestDataPath = @"x:\dummypath\dummy_test.csv";
private static string ModelPath = @"./model.zip";
private static string ModelPath = @"..\..\..\model.zip";

// Set this flag to enable the training process.
private static bool EnableTraining = false;
Expand Down
42 changes: 21 additions & 21 deletions src/mlnet/Templates/Console/MLCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ public virtual string TransformText()
this.Write(this.ToStringHelper.ToStringWithCulture(TestPath));
this.Write("\";\r\n");
}
this.Write(" private static string ModelPath = @\"./model.zip\";\r\n\r\n // Set this " +
"flag to enable the training process.\r\n private static bool EnableTraining" +
" = false;\r\n\r\n static void Main(string[] args)\r\n {\r\n // " +
"Create MLContext to be shared across the model creation workflow objects \r\n " +
" // Set a random seed for repeatable/deterministic results across multiple" +
" trainings.\r\n var mlContext = new MLContext(seed: 1);\r\n\r\n " +
"if (EnableTraining)\r\n {\r\n // Create, Train, Evaluate a" +
"nd Save a model\r\n BuildTrainEvaluateAndSaveModel(mlContext);\r\n " +
" ConsoleHelper.ConsoleWriteHeader(\"=============== End of training p" +
"rocess ===============\");\r\n }\r\n else\r\n {\r\n " +
" ConsoleHelper.ConsoleWriteHeader(\"Skipping the training process. Plea" +
"se set the flag : \'EnableTraining\' to \'true\' to enable the training process.\");\r" +
"\n }\r\n\r\n // Make a single test prediction loading the model" +
" from .ZIP file\r\n TestSinglePrediction(mlContext);\r\n\r\n Con" +
"soleHelper.ConsoleWriteHeader(\"=============== End of process, hit any key to fi" +
"nish ===============\");\r\n Console.ReadKey();\r\n\r\n }\r\n\r\n " +
"private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlContext)\r" +
"\n {\r\n // Data loading\r\n IDataView trainingDataView " +
"= mlContext.Data.ReadFromTextFile<SampleObservation>(\r\n " +
" path: TrainDataPath,\r\n " +
" hasHeader : ");
this.Write(" private static string ModelPath = @\"..\\..\\..\\model.zip\";\r\n\r\n // Se" +
"t this flag to enable the training process.\r\n private static bool EnableT" +
"raining = false;\r\n\r\n static void Main(string[] args)\r\n {\r\n " +
" // Create MLContext to be shared across the model creation workflow objects " +
"\r\n // Set a random seed for repeatable/deterministic results across m" +
"ultiple trainings.\r\n var mlContext = new MLContext(seed: 1);\r\n\r\n " +
" if (EnableTraining)\r\n {\r\n // Create, Train, Eva" +
"luate and Save a model\r\n BuildTrainEvaluateAndSaveModel(mlContext" +
");\r\n ConsoleHelper.ConsoleWriteHeader(\"=============== End of tra" +
"ining process ===============\");\r\n }\r\n else\r\n {" +
"\r\n ConsoleHelper.ConsoleWriteHeader(\"Skipping the training proces" +
"s. Please set the flag : \'EnableTraining\' to \'true\' to enable the training proce" +
"ss.\");\r\n }\r\n\r\n // Make a single test prediction loading th" +
"e model from .ZIP file\r\n TestSinglePrediction(mlContext);\r\n\r\n " +
" ConsoleHelper.ConsoleWriteHeader(\"=============== End of process, hit any ke" +
"y to finish ===============\");\r\n Console.ReadKey();\r\n\r\n }\r\n\r\n " +
" private static ITransformer BuildTrainEvaluateAndSaveModel(MLContext mlCo" +
"ntext)\r\n {\r\n // Data loading\r\n IDataView trainingDa" +
"taView = mlContext.Data.ReadFromTextFile<SampleObservation>(\r\n " +
" path: TrainDataPath,\r\n " +
" hasHeader : ");
this.Write(this.ToStringHelper.ToStringWithCulture(HasHeader.ToString().ToLowerInvariant()));
this.Write(",\r\n separatorChar : \'");
this.Write(this.ToStringHelper.ToStringWithCulture(Regex.Escape(Separator.ToString())));
Expand Down
2 changes: 1 addition & 1 deletion src/mlnet/Templates/Console/MLCodeGen.tt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace <#= Namespace #>
<#if(!string.IsNullOrEmpty(TestPath)){ #>
private static string TestDataPath = @"<#= TestPath #>";
<# } #>
private static string ModelPath = @"./model.zip";
private static string ModelPath = @"..\..\..\model.zip";

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

0 comments on commit 9de92e6

Please sign in to comment.