Skip to content

Commit

Permalink
added nuget sources in generated csproj (dotnet#262)
Browse files Browse the repository at this point in the history
* added nuget sources in csproj

* changed the structure in generated code

* space
  • Loading branch information
srsaggam authored Mar 5, 2019
1 parent 3acd887 commit 1a5161d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="ConsoleHelper.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ namespace MyNamespace
// Create MLContext to be shared across the model creation workflow objects
var mlContext = new MLContext();

// (Optional step) Create, Train, Evaluate and Save the model.zip file
TrainEvaluateAndSaveModel(mlContext);
var command = Command.Predict; // Your desired action here

// Make a single test prediction loading the model from model.zip file
Predict(mlContext);
if (command == Command.Predict)
{
Predict(mlContext);
ConsoleHelper.ConsoleWriteHeader("=============== If you also want to train a model use Command.TrainAndPredict ===============");
}

ConsoleHelper.ConsoleWriteHeader("=============== End of process, hit any key to finish ===============");
if (command == Command.TrainAndPredict)
{
TrainEvaluateAndSaveModel(mlContext);
Predict(mlContext);
}

Console.WriteLine("=============== End of process, hit any key to finish ===============");
Console.ReadKey();
}

private enum Command
{
Predict,
TrainAndPredict
}

private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
Expand Down Expand Up @@ -77,7 +90,7 @@ namespace MyNamespace
mlContext.Model.Save(trainedModel, fs);

Console.WriteLine("The model is saved to {0}", ModelPath);
ConsoleHelper.ConsoleWriteHeader("=============== End of training process ===============");
Console.WriteLine("=============== End of training process ===============");

return trainedModel;
}
Expand Down
25 changes: 19 additions & 6 deletions src/mlnet/Templates/Console/MLCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,28 @@ static void Main(string[] args)
// Create MLContext to be shared across the model creation workflow objects
var mlContext = new MLContext();
// (Optional step) Create, Train, Evaluate and Save the model.zip file
TrainEvaluateAndSaveModel(mlContext);
var command = Command.Predict; // Your desired action here
// Make a single test prediction loading the model from model.zip file
Predict(mlContext);
if (command == Command.Predict)
{
Predict(mlContext);
ConsoleHelper.ConsoleWriteHeader(""=============== If you also want to train a model use Command.TrainAndPredict ==============="");
}
ConsoleHelper.ConsoleWriteHeader(""=============== End of process, hit any key to finish ==============="");
if (command == Command.TrainAndPredict)
{
TrainEvaluateAndSaveModel(mlContext);
Predict(mlContext);
}
Console.WriteLine(""=============== End of process, hit any key to finish ==============="");
Console.ReadKey();
}
private enum Command
{
Predict,
TrainAndPredict
}
private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
Expand Down Expand Up @@ -184,7 +197,7 @@ private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
mlContext.Model.Save(trainedModel, fs);
Console.WriteLine(""The model is saved to {0}"", ModelPath);
ConsoleHelper.ConsoleWriteHeader(""=============== End of training process ==============="");
Console.WriteLine(""=============== End of training process ==============="");
return trainedModel;
}
Expand Down
25 changes: 19 additions & 6 deletions src/mlnet/Templates/Console/MLCodeGen.tt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,28 @@ namespace <#= Namespace #>
// Create MLContext to be shared across the model creation workflow objects
var mlContext = new MLContext();

// (Optional step) Create, Train, Evaluate and Save the model.zip file
TrainEvaluateAndSaveModel(mlContext);
var command = Command.Predict; // Your desired action here

// Make a single test prediction loading the model from model.zip file
Predict(mlContext);
if (command == Command.Predict)
{
Predict(mlContext);
ConsoleHelper.ConsoleWriteHeader("=============== If you also want to train a model use Command.TrainAndPredict ===============");
}

ConsoleHelper.ConsoleWriteHeader("=============== End of process, hit any key to finish ===============");
if (command == Command.TrainAndPredict)
{
TrainEvaluateAndSaveModel(mlContext);
Predict(mlContext);
}

Console.WriteLine("=============== End of process, hit any key to finish ===============");
Console.ReadKey();
}

private enum Command
{
Predict,
TrainAndPredict
}

private static ITransformer TrainEvaluateAndSaveModel(MLContext mlContext)
Expand Down Expand Up @@ -123,7 +136,7 @@ if(string.IsNullOrEmpty(TestPath)){ #>
mlContext.Model.Save(trainedModel, fs);

Console.WriteLine("The model is saved to {0}", ModelPath);
ConsoleHelper.ConsoleWriteHeader("=============== End of training process ===============");
Console.WriteLine("=============== End of training process ===============");

return trainedModel;
}
Expand Down
6 changes: 6 additions & 0 deletions src/mlnet/Templates/Console/MLProjectGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public virtual string TransformText()
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<Compile Include=""Program.cs"" />
<Compile Include=""ConsoleHelper.cs"" />
Expand Down
6 changes: 6 additions & 0 deletions src/mlnet/Templates/Console/MLProjectGen.tt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="ConsoleHelper.cs" />
Expand Down

0 comments on commit 1a5161d

Please sign in to comment.