Skip to content

Fixed bugs in OptionalColumnTransform and ColumnSelecting #4887

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 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 3 additions & 4 deletions src/Microsoft.ML.Data/Transforms/ColumnSelecting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,19 +732,18 @@ IDataTransform ITransformTemplate.ApplyToData(IHostEnvironment env, IDataView ne

public void SaveAsOnnx(OnnxContext ctx)
{
var droppedCols = new HashSet<int>(Enumerable.Range(0, InputSchema.Count));

var outputToInputMap = _mapper.OutputToInputMap;
for(int i = 0; i < outputToInputMap.Length; i++)
{
var srcCol = InputSchema[outputToInputMap[i]];
var dstCol = OutputSchema[i];
if (!ctx.ContainsColumn(srcCol.Name) || dstCol.IsHidden)
continue;

var srcVariable = ctx.GetVariableName(srcCol.Name);
var dstVariable = ctx.AddIntermediateVariable(dstCol.Type, dstCol.Name, true);
string opType = "Identity";
ctx.CreateNode(opType, srcVariable, dstVariable, ctx.GetNodeName(opType), "");

droppedCols.Remove(srcCol.Index);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Microsoft.ML.Transforms/OptionalColumnTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,12 @@ public void SaveAsOnnx(OnnxContext ctx)
if (!ctx.ContainsColumn(inputColumnName))
continue;

if (!SaveAsOnnxCore(ctx, ctx.GetVariableName(inputColumnName), _bindings.ColumnTypes[iinfo]))
// If there is already a column of this name, don't add this column as an OptionalColumn/Initializer
var srcVariableName = ctx.GetVariableName(inputColumnName);
if (srcVariableName != inputColumnName)
continue;

if (!SaveAsOnnxCore(ctx, srcVariableName, _bindings.ColumnTypes[iinfo]))
ctx.RemoveColumn(inputColumnName, true);
}
}
Expand Down