Skip to content

Commit

Permalink
fixes based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgsharp committed Mar 3, 2021
1 parent d251bb5 commit e464102
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/Microsoft.ML.TensorFlow/TensorflowTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ internal TensorFlowTransformer(IHostEnvironment env, TensorFlowModel tfModelInfo
/// <param name="outputColumnNames">The output columns to generate. Names must match model specifications. Data types are inferred from model.</param>
/// <param name="addBatchDimensionInput">Add a batch dimension to the input e.g. input = [224, 224, 3] => [-1, 224, 224, 3].
/// This parameter is used to deal with models that have unknown shape but the internal operators in the model require data to have batch dimension as well.</param>
internal TensorFlowTransformer(IHostEnvironment env, TensorFlowModel tfModelInfo, string[] outputColumnNames, string[] inputColumnNames, bool addBatchDimensionInput = false)
: this(env, tfModelInfo.Session, outputColumnNames, inputColumnNames, IsSavedModel(env, tfModelInfo.ModelPath) ? tfModelInfo.ModelPath : null, false, addBatchDimensionInput)
/// <param name="treatOutputAsBatched">If the first dimension of the output is unknown, should it be treated as batched or not.</param>
internal TensorFlowTransformer(IHostEnvironment env, TensorFlowModel tfModelInfo, string[] outputColumnNames, string[] inputColumnNames, bool addBatchDimensionInput = false, bool treatOutputAsBatched = true)
: this(env, tfModelInfo.Session, outputColumnNames, inputColumnNames, IsSavedModel(env, tfModelInfo.ModelPath) ? tfModelInfo.ModelPath : null, false, addBatchDimensionInput, treatOutputAsBatched: treatOutputAsBatched)
{
}

Expand Down Expand Up @@ -898,9 +899,9 @@ internal sealed class Options : TransformInputBase
/// If the first dimension of the output is unknown, should it be treated as batched or not. e.g. output = [-1] will be read as a vector of unknown length when this is false.
/// </summary>
/// <remarks>
/// This parameter is used to deal with models that have unknown output shape and it needs to be interpreted in ML.NET as a vector of unkown length and not as a batch dimension.
/// This parameter is used to deal with models that have unknown output shape and it needs to be interpreted in ML.NET as a vector of unknown length and not as a batch dimension.
/// </remarks>
[Argument(ArgumentType.AtMostOnce, HelpText = "If the first dimension of the output is unknown, should it be treated as batched or not. e.g. output = [-1] will be read as a vector of unkown length when this is false.", SortOrder = 17)]
[Argument(ArgumentType.AtMostOnce, HelpText = "If the first dimension of the output is unknown, should it be treated as batched or not. e.g. output = [-1] will be read as a vector of unknown length when this is false.", SortOrder = 17)]
public bool TreatOutputAsBatched = true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.TensorFlow/TensorflowUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ internal static DataViewSchema GetModelSchema(IExceptionContext ectx, Graph grap
columnType = new VectorDataViewType(mlType, tensorShape[0] > 0 ? tensorShape : tensorShape.Skip(1).ToArray());
}
// When treatOutputAsBatched is false, if the first value is less than 0 we want to set it to 0. TensorFlow
// represents an unkown size as -1, but ML.NET represents it as 0 so we need to convert it.
// I.E. if the input dimensions are [-1, 5], ML.NET will read the -1 as a dimension of unkown length, and so the ML.NET
// data type will be a vector of 2 dimensions, where the first dimension is unkown and the second has a length of 5.
// represents an unknown size as -1, but ML.NET represents it as 0 so we need to convert it.
// I.E. if the input dimensions are [-1, 5], ML.NET will read the -1 as a dimension of unknown length, and so the ML.NET
// data type will be a vector of 2 dimensions, where the first dimension is unknown and the second has a length of 5.
else
{
if (tensorShape[0] < 0)
Expand Down
2 changes: 1 addition & 1 deletion test/BaselineOutput/Common/EntryPoints/core_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23617,7 +23617,7 @@
{
"Name": "TreatOutputAsBatched",
"Type": "Bool",
"Desc": "If the first dimension of the output is unknown, should it be treated as batched or not. e.g. output = [-1] will be read as a vector of unkown length when this is false.",
"Desc": "If the first dimension of the output is unknown, should it be treated as batched or not. e.g. output = [-1] will be read as a vector of unknown length when this is false.",
"Required": false,
"SortOrder": 17.0,
"IsNullable": false,
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.ML.Tests/TensorFlowEstimatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void TestTensorFlow()
Assert.Equal(4, numRows);
}
}

[TensorFlowFact]
public void TreatOutputAsBatched()
{
Expand Down Expand Up @@ -211,7 +211,7 @@ public void TreatOutputAsBatched()
var schema = pipe.Fit(data).Transform(data).Schema;

// The dimensions of the output with treatOutputAsBatched set to false should be * 10
// as the first dimension of -1 is treated as an unkown dimension.
// as the first dimension of -1 is treated as an unknown dimension.
Assert.Equal(new VectorDataViewType(NumberDataViewType.Single, 0, 10), schema["Output"].Type);

// Note that CamelCase column names are there to match the TF graph node names.
Expand Down

0 comments on commit e464102

Please sign in to comment.