Skip to content

Fix scalar and no-rank/no-shape tensor validation when using the TensorFlow predictor  #1310

@RobertLucian

Description

@RobertLucian

Description

2 properties of a tensor (in TensorFlow) are the rank and shape. Right now, when using the TensorFlow predictor, only the 2 following kinds of tensors are supported:

  • Tensors with known rank and shape. Such as (3, 224, 224).
  • Tensors with known rank and unknown shape. Such as (3, -1, -1).

Reproduce

When tensors have the following properties, the validation will fail, when in reality, it shouldn't:

  • Tensors with no rank and empty shape - for scalars. Such as ().
  • Tensors with unknown rank and shape. Such as (-1, -1, -1, ...).

When an input tensor has the above properties, the following error pops up the logs cortex logs <api-name>.

Traceback (most recent call last):
File "/src/cortex/serve/serve.py", line 282, in start_fn
tf_serving_host=tf_serving_host, tf_serving_port=tf_serving_port
File "/src/cortex/lib/type/predictor.py", line 72, in initialize_client
client = TensorFlowClient(tf_serving_address, self.models)
File "/src/cortex/lib/client/tensorflow.py", line 48, in init
self._signatures, get_model_signature_map(models)
File "/src/cortex/lib/client/tensorflow.py", line 186, in extract_signatures
signature_defs[model_name], signature_keys[model_name], model_name,
File "/src/cortex/lib/client/tensorflow.py", line 246, in extract_signature
"shape": [int(dim["size"]) for dim in input_metadata["tensorShape"]["dim"]],
KeyError: 'dim'

Additional

References that show that no-rank/no-shape and scalar tensors do indeed exist and are used:

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions