Skip to content

Commit

Permalink
adding test - onehothas
Browse files Browse the repository at this point in the history
  • Loading branch information
Lynx1820 committed May 8, 2020
1 parent 59dbdea commit d154d19
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/Microsoft.ML.Tests/OnnxConversionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using Microsoft.ML.Data;
using Microsoft.ML.EntryPoints;
using Microsoft.ML.Model.OnnxConverter;
Expand Down Expand Up @@ -125,6 +124,9 @@ private class BreastCancerCatFeatureExample

[LoadColumn(2)]
public string F2;

[LoadColumn(3, 7), VectorType(6)]
public string[] F3;
}

private class BreastCancerMulticlassExample
Expand Down Expand Up @@ -1162,6 +1164,37 @@ public void PcaOnnxConversionTest()
Done();
}

[Fact]
public void OneHotHashEncodingOnnxConversionTest()
{
var mlContext = new MLContext();
string dataPath = GetDataPath("breast-cancer.txt");

var dataView = ML.Data.LoadFromTextFile<BreastCancerCatFeatureExample>(dataPath);
var pipe = ML.Transforms.Categorical.OneHotHashEncoding(new[]{
new OneHotHashEncodingEstimator.ColumnOptions("Output", "F3", useOrderedHashing:false),
});
var model = pipe.Fit(dataView);
var transformedData = model.Transform(dataView);
var onnxModel = mlContext.Model.ConvertToOnnxProtobuf(model, dataView);

var onnxFileName = "OneHotHashEncoding.onnx";
var onnxModelPath = GetOutputPath(onnxFileName);
SaveOnnxModel(onnxModel, onnxModelPath, null);

if (IsOnnxRuntimeSupported())
{
// Evaluate the saved ONNX model using the data used to train the ML.NET pipeline.
string[] inputNames = onnxModel.Graph.Input.Select(valueInfoProto => valueInfoProto.Name).ToArray();
string[] outputNames = onnxModel.Graph.Output.Select(valueInfoProto => valueInfoProto.Name).ToArray();
var onnxEstimator = mlContext.Transforms.ApplyOnnxModel(outputNames, inputNames, onnxModelPath);
var onnxTransformer = onnxEstimator.Fit(dataView);
var onnxResult = onnxTransformer.Transform(dataView);
CompareSelectedColumns<float>("Output", "Output", transformedData, onnxResult);
}
Done();
}

[Theory]
[CombinatorialData]
// Due to lack of Onnxruntime support, long/ulong, double, floats, and OrderedHashing are not supported.
Expand Down

0 comments on commit d154d19

Please sign in to comment.