Skip to content

Alternate solution for ColumnConcatenatingTransformer #4875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
adding baselines
  • Loading branch information
Keren Fuentes committed Feb 25, 2020
commit 29f83704ce22607530079e6d199d07fb4bee286c
Original file line number Diff line number Diff line change
Expand Up @@ -896,15 +896,14 @@ public void SaveAsOnnx(OnnxContext ctx)
Host.CheckValue(ctx, nameof(ctx));
Contracts.Assert(CanSaveOnnx(ctx));

string opType = "FeatureVectorizer";
for (int iinfo = 0; iinfo < _columns.Length; ++iinfo)
{
var colInfo = _parent._columns[iinfo];
var boundCol = _columns[iinfo];

string outName = colInfo.Name;
var outColType = boundCol.OutputType;
if (!outColType.IsKnownSize)
if ((!outColType.IsKnownSize) || (!(outColType.GetItemType() is NumberDataViewType)))
{
ctx.RemoveColumn(outName, false);
continue;
Expand All @@ -925,15 +924,18 @@ public void SaveAsOnnx(OnnxContext ctx)
InputSchema[srcIndex].Type.GetValueCount()));
}

var dstVariableName = ctx.AddIntermediateVariable(outColType, outName, true);
var vectorizerOutputName = ctx.AddIntermediateVariable(null, "VectorFeaturizerOutput", true);
string opType = "FeatureVectorizer";
int outVectorSize = (int)inputList.Sum(x => x.Value);
var vectorizerOutputType = new VectorDataViewType(NumberDataViewType.Single, outVectorSize);
var vectorizerOutputName = ctx.AddIntermediateVariable(vectorizerOutputType, "VectorFeaturizerOutput");
var node = ctx.CreateNode(opType, inputList.Select(t => t.Key),
new[] { vectorizerOutputName }, ctx.GetNodeName(opType));
node.AddAttribute("inputdimensions", inputList.Select(x => x.Value));

opType = "Cast";
var dstVectorType = new VectorDataViewType(outColType.GetItemType() as PrimitiveDataViewType, outVectorSize);
var dstVariableName = ctx.AddIntermediateVariable(dstVectorType, outName);
var castNode = ctx.CreateNode(opType, vectorizerOutputName, dstVariableName, ctx.GetNodeName(opType), "");
var t = InternalDataKindExtensions.ToInternalDataKind(DataKind.Double).ToType();
castNode.AddAttribute("to", outColType.ItemType.RawType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,35 @@
"F1",
"F22"
],
"output": [
"VectorFeaturizerOutput"
],
"name": "FeatureVectorizer",
"opType": "FeatureVectorizer",
"attribute": [
{
"name": "inputdimensions",
"ints": [
"1",
"10"
],
"type": "INTS"
}
],
"domain": "ai.onnx.ml"
},
{
"input": [
"VectorFeaturizerOutput"
],
"output": [
"Features"
],
"name": "Concat",
"opType": "Concat",
"name": "Cast1",
"opType": "Cast",
"attribute": [
{
"name": "axis",
"name": "to",
"i": "1",
"type": "INT"
}
Expand Down Expand Up @@ -431,7 +452,7 @@
"output": [
"PredictedLabel"
],
"name": "Cast1",
"name": "Cast2",
"opType": "Cast",
"attribute": [
{
Expand Down Expand Up @@ -638,6 +659,24 @@
}
}
},
{
"name": "VectorFeaturizerOutput",
"type": {
"tensorType": {
"elemType": 1,
"shape": {
"dim": [
{
"dimValue": "-1"
},
{
"dimValue": "11"
}
]
}
}
}
},
{
"name": "Features",
"type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,35 @@
"F1",
"F21"
],
"output": [
"VectorFeaturizerOutput"
],
"name": "FeatureVectorizer",
"opType": "FeatureVectorizer",
"attribute": [
{
"name": "inputdimensions",
"ints": [
"8",
"9"
],
"type": "INTS"
}
],
"domain": "ai.onnx.ml"
},
{
"input": [
"VectorFeaturizerOutput"
],
"output": [
"Features"
],
"name": "Concat",
"opType": "Concat",
"name": "Cast1",
"opType": "Cast",
"attribute": [
{
"name": "axis",
"name": "to",
"i": "1",
"type": "INT"
}
Expand Down Expand Up @@ -757,7 +778,7 @@
"output": [
"PredictedLabel"
],
"name": "Cast1",
"name": "Cast2",
"opType": "Cast",
"attribute": [
{
Expand Down Expand Up @@ -946,6 +967,24 @@
}
}
},
{
"name": "VectorFeaturizerOutput",
"type": {
"tensorType": {
"elemType": 1,
"shape": {
"dim": [
{
"dimValue": "-1"
},
{
"dimValue": "17"
}
]
}
}
}
},
{
"name": "Features",
"type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,35 @@
"F1",
"F22"
],
"output": [
"VectorFeaturizerOutput"
],
"name": "FeatureVectorizer",
"opType": "FeatureVectorizer",
"attribute": [
{
"name": "inputdimensions",
"ints": [
"1",
"10"
],
"type": "INTS"
}
],
"domain": "ai.onnx.ml"
},
{
"input": [
"VectorFeaturizerOutput"
],
"output": [
"Features"
],
"name": "Concat",
"opType": "Concat",
"name": "Cast1",
"opType": "Cast",
"attribute": [
{
"name": "axis",
"name": "to",
"i": "1",
"type": "INT"
}
Expand Down Expand Up @@ -384,7 +405,7 @@
"output": [
"PredictedLabel"
],
"name": "Cast1",
"name": "Cast2",
"opType": "Cast",
"attribute": [
{
Expand Down Expand Up @@ -871,6 +892,24 @@
}
}
},
{
"name": "VectorFeaturizerOutput",
"type": {
"tensorType": {
"elemType": 1,
"shape": {
"dim": [
{
"dimValue": "-1"
},
{
"dimValue": "11"
}
]
}
}
}
},
{
"name": "Features",
"type": {
Expand Down