From c073e6b3bcb271afe002cd1fb354bb2309551a28 Mon Sep 17 00:00:00 2001 From: LittleLittleCloud Date: Tue, 28 Apr 2020 12:25:38 -0700 Subject: [PATCH 1/3] upgrade to 3.1 --- .../Templates/Console/PredictProject.cs | 2 +- .../Templates/Console/PredictProject.tt | 2 +- ...s.AzureCodeGeneratorTest.test.ConsoleApp.csproj.approved.txt | 2 +- ...CodeGeneratorTest.CodeGenTest.ConsoleApp.csproj.approved.txt | 2 +- ...GeneratorTests.ConsoleAppProjectFileContentTest.approved.txt | 2 +- ...eConsoleAppProjectContents_VerifyPredictProject.approved.txt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.cs b/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.cs index 96c4bbf124..29f288a076 100644 --- a/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.cs +++ b/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.cs @@ -27,7 +27,7 @@ internal partial class PredictProject : PredictProjectBase public virtual string TransformText() { this.Write("\r\n\r\n \r\n Exe\r\n netcoreapp2.1\r\n \r\n netcoreapp3.1\r\n \r\n \r\n \r\n"); diff --git a/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.tt b/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.tt index 1dd932085e..15e82d409c 100644 --- a/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.tt +++ b/src/Microsoft.ML.CodeGenerator/Templates/Console/PredictProject.tt @@ -8,7 +8,7 @@ Exe - netcoreapp2.1 + netcoreapp3.1 diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.test.ConsoleApp.csproj.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.test.ConsoleApp.csproj.approved.txt index 66e5ca3695..f94467d5dc 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.test.ConsoleApp.csproj.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.test.ConsoleApp.csproj.approved.txt @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.1 diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.CodeGenTest.ConsoleApp.csproj.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.CodeGenTest.ConsoleApp.csproj.approved.txt index 23fa52e0c1..5a0f249e82 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.CodeGenTest.ConsoleApp.csproj.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.CodeGenTest.ConsoleApp.csproj.approved.txt @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.1 diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsoleAppProjectFileContentTest.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsoleAppProjectFileContentTest.approved.txt index 9ef4077dee..97df9ea672 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsoleAppProjectFileContentTest.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsoleAppProjectFileContentTest.approved.txt @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.1 diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateConsoleAppProjectContents_VerifyPredictProject.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateConsoleAppProjectContents_VerifyPredictProject.approved.txt index 14a45f8c0c..e261bed0fd 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateConsoleAppProjectContents_VerifyPredictProject.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateConsoleAppProjectContents_VerifyPredictProject.approved.txt @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.1 From 8f0fc1a59dd3aa6186ec4e94f9cccf93fab4dae4 Mon Sep 17 00:00:00 2001 From: LittleLittleCloud Date: Tue, 28 Apr 2020 12:31:31 -0700 Subject: [PATCH 2/3] write inline data using invariantCulture --- src/Microsoft.ML.CodeGenerator/Utils.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.ML.CodeGenerator/Utils.cs b/src/Microsoft.ML.CodeGenerator/Utils.cs index 216097064c..075bc577ce 100644 --- a/src/Microsoft.ML.CodeGenerator/Utils.cs +++ b/src/Microsoft.ML.CodeGenerator/Utils.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -101,7 +102,7 @@ internal static string GetValueFromColumn(DataViewRowCursor rowCursor, DataVi return "Single.NegativeInfinity"; } - return f?.ToString() + "F"; + return f?.ToString(CultureInfo.InvariantCulture) + "F"; } if (val is bool) From 9ee36789514fde4a66b49a46b641814836411937 Mon Sep 17 00:00:00 2001 From: LittleLittleCloud Date: Thu, 10 Dec 2020 10:56:37 -0800 Subject: [PATCH 3/3] fix mlnet build error --- .../Templates/Console/ConsumeModel.cs | 5 +++-- .../Templates/Console/ConsumeModel.tt | 4 ++-- ...Tests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt | 2 +- ....AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt | 4 ++-- ...ctDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt | 4 ++-- ...leCodeGeneratorTests.ConsumeModelContentTest.approved.txt | 2 +- ...erateModelProjectContents_VerifyConsumeModel.approved.txt | 2 +- .../TemplateTest.TestConsumeModel_AzureImage.approved.txt | 4 ++-- ...teTest.TestConsumeModel_AzureObjectDetection.approved.txt | 4 ++-- ...onsumeModel_NotAzureImage_NotObjectDetection.approved.txt | 2 +- 10 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs index 6ba08042c9..e71626d937 100644 --- a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs +++ b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.cs @@ -41,11 +41,12 @@ public class ConsumeModel { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("""); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, """); this.Write(this.ToStringHelper.ToStringWithCulture(MLNetModelName)); this.Write("\");\r\n"); if(IsAzureImage || IsAzureObjectDetection){ - this.Write(" \r\n public static string OnnxModelPath = Path.GetFullPath(\""); + this.Write(" \r\n public static string OnnxModelPath = Path.Combine(System.AppContext.Ba" + + "seDirectory, \""); this.Write(this.ToStringHelper.ToStringWithCulture(OnnxModelName)); this.Write("\");\r\n"); } diff --git a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt index 8c3d11568d..7735b15ee9 100644 --- a/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt +++ b/src/Microsoft.ML.CodeGenerator/Templates/Console/ConsumeModel.tt @@ -23,9 +23,9 @@ namespace <#= Namespace #>.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("<#= MLNetModelName #>"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "<#= MLNetModelName #>"); <#if(IsAzureImage || IsAzureObjectDetection){ #> - public static string OnnxModelPath = Path.GetFullPath("<#= OnnxModelName #>"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "<#= OnnxModelName #>"); <#} #> // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt index 0706528fe5..27940abbc5 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureCodeGeneratorTest.ConsumeModel.cs.approved.txt @@ -14,7 +14,7 @@ namespace Test.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("\path\to\model"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "\path\to\model"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt index 102d17059d..95db062089 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureImageCodeGeneratorTest.ConsumeModel.cs.approved.txt @@ -14,9 +14,9 @@ namespace CodeGenTest.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("/path/to/model"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/model"); - public static string OnnxModelPath = Path.GetFullPath("/path/to/onnxModel"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/onnxModel"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt index 102d17059d..95db062089 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.AzureObjectDetectionCodeGeneratorTest.ConsumeModel.cs.approved.txt @@ -14,9 +14,9 @@ namespace CodeGenTest.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("/path/to/model"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/model"); - public static string OnnxModelPath = Path.GetFullPath("/path/to/onnxModel"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "/path/to/onnxModel"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt index fb1e37cb14..4f0b83618b 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.ConsumeModelContentTest.approved.txt @@ -18,7 +18,7 @@ namespace TestNamespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("x:\models\model.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "x:\models\model.zip"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt index fb1e37cb14..4f0b83618b 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/ConsoleCodeGeneratorTests.Recommendation_GenerateModelProjectContents_VerifyConsumeModel.approved.txt @@ -18,7 +18,7 @@ namespace TestNamespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("x:\models\model.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "x:\models\model.zip"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt index 102796208a..39829e5c2c 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureImage.approved.txt @@ -14,9 +14,9 @@ namespace Namespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip"); - public static string OnnxModelPath = Path.GetFullPath("onnx.onnx"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "onnx.onnx"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt index a4c874b77b..68be854510 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_AzureObjectDetection.approved.txt @@ -14,9 +14,9 @@ namespace Namespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip"); - public static string OnnxModelPath = Path.GetFullPath("onnx.onnx"); + public static string OnnxModelPath = Path.Combine(System.AppContext.BaseDirectory, "onnx.onnx"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app diff --git a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt index b1e4146d53..30fa1b7dfb 100644 --- a/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt +++ b/test/Microsoft.ML.CodeGenerator.Tests/ApprovalTests/TemplateTest.TestConsumeModel_NotAzureImage_NotObjectDetection.approved.txt @@ -14,7 +14,7 @@ namespace Namespace.Model { private static Lazy> PredictionEngine = new Lazy>(CreatePredictionEngine); - public static string MLNetModelPath = Path.GetFullPath("mlmodel.zip"); + public static string MLNetModelPath = Path.Combine(System.AppContext.BaseDirectory, "mlmodel.zip"); // For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume // Method for consuming model in your app