Skip to content

TensorFlow transform would throw on non-vector input #1542

Description

@TomFinley

In the process of working on #1533, I found the following code in the tensorflow transform.

_isInputVector[i] = type.IsVector;
var expectedType = TensorFlowUtils.Tf2MlNetType(_parent.TFInputTypes[i]);
if (type.ItemType != expectedType)
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", _parent.Inputs[i], expectedType.ToString(), type.ToString());
var originalShape = _parent.TFInputShapes[i];
var shape = originalShape.ToIntArray();
var colTypeDims = Enumerable.Range(0, type.AsVector.DimCount + 1).Select(d => d == 0 ? 1 : (long)type.AsVector.GetDim(d - 1)).ToArray();
if (shape == null)
_fullySpecifiedShapes[i] = new TFShape(colTypeDims);
else if (type.AsVector.DimCount == 1)

Consider the above code. We have at line 834 this assignment to a boolean value depending on whether the input is of type vector, or not. This strongly suggests that the transform can accomodate non-vector types. However at lines 841 and 844, we have this type.AsVector.DimCount. Now, AsVector will be null in the case where the type is not a vector of course, so this would throw a null reference exception if we were to ever feed this transform a non-vector value.

So, there's something wrong here. Unfortunately the intent of what the author meant to write is somewhat hidden from me, so perhaps whoever wrote this code could check this out. Maybe even write a test to test this condition.

Metadata

Metadata

Assignees

Labels

P1Priority of the issue for triage purpose: Needs to be fixed soon.bugSomething isn't workingneed infoThis issue needs more info before triage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions