Skip to content

Commit 50505e3

Browse files
committed
further cleanup and fix build
1 parent a99476b commit 50505e3

File tree

13 files changed

+105
-35
lines changed

13 files changed

+105
-35
lines changed

src/Microsoft.ML.Data/Transforms/ColumnSelecting.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ namespace Microsoft.ML.Transforms
4040
/// </summary>
4141
public sealed class ColumnSelectingEstimator : TrivialEstimator<ColumnSelectingTransformer>
4242
{
43-
public static class Defaults
43+
[BestFriend]
44+
internal static class Defaults
4445
{
4546
public const bool KeepHidden = false;
4647
public const bool IgnoreMissing = false;

src/Microsoft.ML.OnnxTransform/Microsoft.ML.OnnxTransform.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<IncludeInPackage>Microsoft.ML.OnnxTransform</IncludeInPackage>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<ApplicationIcon />
8+
<Win32Resource />
79
</PropertyGroup>
810

911
<ItemGroup>

src/Microsoft.ML.OnnxTransform/OnnxTransform.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ internal sealed class Options : TransformInputBase
8888
internal const string ShortName = "Onnx";
8989
internal const string LoaderSignature = "OnnxTransform";
9090

91-
public readonly string[] Inputs;
92-
public readonly string[] Outputs;
93-
public readonly ColumnType[] OutputTypes;
91+
internal readonly string[] Inputs;
92+
internal readonly string[] Outputs;
93+
internal readonly ColumnType[] OutputTypes;
9494

9595
private static VersionInfo GetVersionInfo()
9696
{
@@ -512,7 +512,7 @@ public NamedOnnxValue GetNamedOnnxValue()
512512
}
513513

514514
/// <summary>
515-
/// A class implementing the estimator interface of the OnnxTransform.
515+
/// A class implementing the estimator interface of the <see cref="OnnxTransformer"/>.
516516
/// </summary>
517517
public sealed class OnnxScoringEstimator : TrivialEstimator<OnnxTransformer>
518518
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.CompilerServices;
6+
using Microsoft.ML;
7+
8+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.DnnImageFeaturizer.AlexNet" + PublicKey.Value)]
9+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.DnnImageFeaturizer.ResNet101" + PublicKey.Value)]
10+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.DnnImageFeaturizer.ResNet18" + PublicKey.Value)]
11+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.DnnImageFeaturizer.ResNet50" + PublicKey.Value)]
12+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.OnnxTransform.StaticPipe" + PublicKey.Value)]
13+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Runtime.CompilerServices;
6+
using Microsoft.ML;
7+
8+
[assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.TensorFlow.StaticPipe" + PublicKey.Value)]
9+

src/Microsoft.ML.TensorFlow/TensorflowCatalog.cs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ namespace Microsoft.ML
1111
/// <include file='doc.xml' path='doc/members/member[@name="TensorflowTransformer"]/*' />
1212
public static class TensorflowCatalog
1313
{
14+
/// <summary>
15+
/// Scores a dataset using a pre-traiend TensorFlow model located in <paramref name="modelLocation"/>.
16+
/// </summary>
17+
/// <param name="catalog">The transform's catalog.</param>
18+
/// <param name="modelLocation">Location of the TensorFlow model.</param>
19+
/// <param name="inputColumnName"> The name of the model inputs.</param>
20+
/// <param name="outputColumnName">The name of the requested model outputs.</param>
21+
/// <example>
22+
/// <format type="text/markdown">
23+
/// <![CDATA[
24+
/// [!code-csharp[ScoreTensorFlowModel](~/../docs/samples/docs/samples/Microsoft.ML.Samples/Dynamic/TensorFlowTransform.cs)]
25+
/// ]]>
26+
/// </format>
27+
/// </example>
28+
public static TensorFlowEstimator ScoreTensorFlowModel(this TransformsCatalog catalog,
29+
string modelLocation,
30+
string outputColumnName,
31+
string inputColumnName)
32+
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), new[] { outputColumnName }, new[] { inputColumnName }, modelLocation);
33+
1434
/// <summary>
1535
/// Scores a dataset using a pre-traiend TensorFlow model located in <paramref name="modelLocation"/>.
1636
/// </summary>
@@ -31,6 +51,19 @@ public static TensorFlowEstimator ScoreTensorFlowModel(this TransformsCatalog ca
3151
string[] inputColumnNames)
3252
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), outputColumnNames, inputColumnNames, modelLocation);
3353

54+
/// <summary>
55+
/// Scores a dataset using a pre-traiend TensorFlow model specified via <paramref name="tensorFlowModel"/>.
56+
/// </summary>
57+
/// <param name="catalog">The transform's catalog.</param>
58+
/// <param name="tensorFlowModel">The pre-trained TensorFlow model.</param>
59+
/// <param name="inputColumnName"> The name of the model inputs.</param>
60+
/// <param name="outputColumnName">The name of the requested model outputs.</param>
61+
public static TensorFlowEstimator ScoreTensorFlowModel(this TransformsCatalog catalog,
62+
TensorFlowModelInfo tensorFlowModel,
63+
string outputColumnName,
64+
string inputColumnName)
65+
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), new[] { outputColumnName }, new[] { inputColumnName }, tensorFlowModel);
66+
3467
/// <summary>
3568
/// Scores a dataset using a pre-traiend TensorFlow model specified via <paramref name="tensorFlowModel"/>.
3669
/// </summary>
@@ -49,20 +82,20 @@ public static TensorFlowEstimator ScoreTensorFlowModel(this TransformsCatalog ca
4982
/// The model is specified in the <see cref="TensorFlowTransformer.Options.ModelLocation"/>.
5083
/// </summary>
5184
/// <param name="catalog">The transform's catalog.</param>
52-
/// <param name="args">The <see cref="TensorFlowTransformer.Options"/> specifying the inputs and the settings of the <see cref="TensorFlowEstimator"/>.</param>
85+
/// <param name="options">The <see cref="TensorFlowTransformer.Options"/> specifying the inputs and the settings of the <see cref="TensorFlowEstimator"/>.</param>
5386
public static TensorFlowEstimator TensorFlow(this TransformsCatalog catalog,
54-
TensorFlowTransformer.Options args)
55-
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), args);
87+
TensorFlowTransformer.Options options)
88+
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), options);
5689

5790
/// <summary>
5891
/// Scores or retrains (based on setting of the <see cref="TensorFlowTransformer.Options.ReTrain"/>) a pre-traiend TensorFlow model specified via <paramref name="tensorFlowModel"/>.
5992
/// </summary>
6093
/// <param name="catalog">The transform's catalog.</param>
61-
/// <param name="args">The <see cref="TensorFlowTransformer.Options"/> specifying the inputs and the settings of the <see cref="TensorFlowEstimator"/>.</param>
94+
/// <param name="options">The <see cref="TensorFlowTransformer.Options"/> specifying the inputs and the settings of the <see cref="TensorFlowEstimator"/>.</param>
6295
/// <param name="tensorFlowModel">The pre-trained TensorFlow model.</param>
6396
public static TensorFlowEstimator TensorFlow(this TransformsCatalog catalog,
64-
TensorFlowTransformer.Options args,
97+
TensorFlowTransformer.Options options,
6598
TensorFlowModelInfo tensorFlowModel)
66-
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), args, tensorFlowModel);
99+
=> new TensorFlowEstimator(CatalogUtils.GetEnvironment(catalog), options, tensorFlowModel);
67100
}
68101
}

src/Microsoft.ML.TensorFlow/TensorflowTransform.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ namespace Microsoft.ML.Transforms
3737
/// <include file='doc.xml' path='doc/members/member[@name="TensorflowTransformer"]/*' />
3838
public sealed class TensorFlowTransformer : RowToRowTransformerBase
3939
{
40+
/// <summary>
41+
/// The settings for the <see cref="TensorFlowTransformer"/>.
42+
/// </summary>
4043
public sealed class Options : TransformInputBase
4144
{
4245
/// <summary>
@@ -148,8 +151,8 @@ public sealed class Options : TransformInputBase
148151
internal readonly TFShape[] TFInputShapes;
149152
internal TFGraph Graph => Session.Graph;
150153

151-
public readonly string[] Inputs;
152-
public readonly string[] Outputs;
154+
internal readonly string[] Inputs;
155+
internal readonly string[] Outputs;
153156

154157
internal static int BatchSize = 1;
155158
internal const string Summary = "Transforms the data using the TensorFlow model.";
@@ -1077,6 +1080,9 @@ public TFTensor GetBufferedBatchTensor()
10771080
}
10781081
}
10791082

1083+
/// <summary>
1084+
/// Estimator for the <see cref="TensorFlowTransformer"/>.
1085+
/// </summary>
10801086
public sealed class TensorFlowEstimator : IEstimator<TensorFlowTransformer>
10811087
{
10821088
private readonly IHost _host;
@@ -1153,7 +1159,7 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
11531159
}
11541160

11551161
/// <summary>
1156-
/// Train and return a <see cref="ITransformer"/>.
1162+
/// Trains and returns a <see cref="TensorFlowTransformer"/>.
11571163
/// </summary>
11581164
public TensorFlowTransformer Fit(IDataView input)
11591165
{

src/Microsoft.ML.Transforms/KeyToVectorMapping.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
namespace Microsoft.ML.Transforms.Conversions
3131
{
32+
/// <summary>
33+
/// Converts the key types back to binary verctors.
34+
/// </summary>
3235
public sealed class KeyToBinaryVectorMappingTransformer : OneToOneTransformerBase
3336
{
3437
internal sealed class Options
@@ -421,6 +424,9 @@ private void EncodeValueToBinary(BufferBuilder<float> bldr, uint value, int bits
421424
}
422425
}
423426

427+
/// <summary>
428+
/// Converts the key types back to binary verctors.
429+
/// </summary>
424430
public sealed class KeyToBinaryVectorMappingEstimator : TrivialEstimator<KeyToBinaryVectorMappingTransformer>
425431
{
426432
internal KeyToBinaryVectorMappingEstimator(IHostEnvironment env, params (string outputColumnName, string inputColumnName)[] columns)

test/Microsoft.ML.OnnxTransformTest/OnnxTransformTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void TestSimpleCase()
120120
var xyData = new List<TestDataXY> { new TestDataXY() { A = new float[inputSize] } };
121121
var stringData = new List<TestDataDifferntType> { new TestDataDifferntType() { data_0 = new string[inputSize] } };
122122
var sizeData = new List<TestDataSize> { new TestDataSize() { data_0 = new float[2] } };
123-
var pipe = new OnnxScoringEstimator(Env, new[] { "softmaxout_1" }, new[] { "data_0" }, modelFile);
123+
var pipe = ML.Transforms.ApplyOnnxModel(modelFile, new[] { "softmaxout_1" }, new[] { "data_0" });
124124

125125
var invalidDataWrongNames = ML.Data.ReadFromEnumerable(xyData);
126126
var invalidDataWrongTypes = ML.Data.ReadFromEnumerable(stringData);
@@ -160,7 +160,7 @@ void TestOldSavingAndLoading(int? gpuDeviceId, bool fallbackToCpu)
160160

161161
var inputNames = new[] { "data_0" };
162162
var outputNames = new[] { "softmaxout_1" };
163-
var est = new OnnxScoringEstimator(Env, outputNames, inputNames, modelFile, gpuDeviceId, fallbackToCpu);
163+
var est = ML.Transforms.ApplyOnnxModel(modelFile, outputNames, inputNames, gpuDeviceId, fallbackToCpu);
164164
var transformer = est.Fit(dataView);
165165
var result = transformer.Transform(dataView);
166166
var resultRoles = new RoleMappedData(result);
@@ -266,7 +266,7 @@ public void OnnxModelScenario()
266266
}
267267
});
268268

269-
var onnx = new OnnxTransformer(env, "softmaxout_1", modelFile, "data_0").Transform(dataView);
269+
var onnx = ML.Transforms.ApplyOnnxModel(modelFile, "softmaxout_1", "data_0").Fit(dataView).Transform(dataView);
270270

271271
onnx.Schema.TryGetColumnIndex("softmaxout_1", out int score);
272272

@@ -299,7 +299,7 @@ public void OnnxModelMultiInput()
299299
inb = new float[] {1,2,3,4,5}
300300
}
301301
});
302-
var onnx = new OnnxTransformer(env, new[] { "outa", "outb" }, new[] { "ina", "inb" }, modelFile).Transform(dataView);
302+
var onnx = ML.Transforms.ApplyOnnxModel(modelFile, new[] { "outa", "outb" }, new[] { "ina", "inb" }).Fit(dataView).Transform(dataView);
303303

304304
onnx.Schema.TryGetColumnIndex("outa", out int scoresa);
305305
onnx.Schema.TryGetColumnIndex("outb", out int scoresb);
@@ -337,7 +337,7 @@ public void TestUnknownDimensions()
337337
new TestDataUnknownDimensions(){input = new float[] {-1.1f, -1.3f, 1.2f }},
338338
};
339339
var idv = mlContext.Data.ReadFromEnumerable(data);
340-
var pipeline = new OnnxScoringEstimator(mlContext, modelFile);
340+
var pipeline = ML.Transforms.ApplyOnnxModel(modelFile);
341341
var transformedValues = pipeline.Fit(idv).Transform(idv);
342342
var predictions = mlContext.CreateEnumerable<PredictionUnknownDimensions>(transformedValues, reuseRowObject: false).ToArray();
343343

test/Microsoft.ML.Tests/OnnxConversionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void SimpleEndToEndOnnxConversionTest()
7272
// Step 3: Evaluate the saved ONNX model using the data used to train the ML.NET pipeline.
7373
string[] inputNames = onnxModel.Graph.Input.Select(valueInfoProto => valueInfoProto.Name).ToArray();
7474
string[] outputNames = onnxModel.Graph.Output.Select(valueInfoProto => valueInfoProto.Name).ToArray();
75-
var onnxEstimator = new OnnxScoringEstimator(mlContext, outputNames, inputNames, onnxModelPath);
75+
var onnxEstimator = mlContext.Transforms.ApplyOnnxModel(onnxModelPath, outputNames, inputNames);
7676
var onnxTransformer = onnxEstimator.Fit(data);
7777
var onnxResult = onnxTransformer.Transform(data);
7878

@@ -156,7 +156,7 @@ public void KmeansOnnxConversionTest()
156156
// Evaluate the saved ONNX model using the data used to train the ML.NET pipeline.
157157
string[] inputNames = onnxModel.Graph.Input.Select(valueInfoProto => valueInfoProto.Name).ToArray();
158158
string[] outputNames = onnxModel.Graph.Output.Select(valueInfoProto => valueInfoProto.Name).ToArray();
159-
var onnxEstimator = new OnnxScoringEstimator(mlContext, outputNames, inputNames, onnxModelPath);
159+
var onnxEstimator = mlContext.Transforms.ApplyOnnxModel(onnxModelPath, outputNames, inputNames);
160160
var onnxTransformer = onnxEstimator.Fit(data);
161161
var onnxResult = onnxTransformer.Transform(data);
162162
CompareSelectedR4VectorColumns("Score", "Score0", transformedData, onnxResult, 3);

0 commit comments

Comments
 (0)