W3cubDocs

/TensorFlow Python

tf.contrib.lite.OpHint

Class OpHint

Defined in tensorflow/contrib/lite/python/op_hint.py.

A class that helps build tflite function invocations.

It allows you to take a bunch of TensorFlow ops and annotate the construction such that toco knows how to convert it to tflite. This embeds a pseudo function in a TensorFlow graph. This allows embedding high-level API usage information in a lower level TensorFlow implementation so that an alternative implementation can be substituted later.

Essentially, any "input" into this pseudo op is fed into an identity, and attributes are added to that input before being used by the constituent ops that make up the pseudo op. A similar process is done to any output that is to be exported from the current op.

TODO(aselle): When TensorFlow functions functionality works for arbitrary constructs, this mechanism can be retired and changed to use python defun's.

Methods

__init__

__init__(
    function_name,
    **kwargs
)

Create a OpHint.

Args:

  • function_name: Name of the function (the custom op name in tflite)
  • **kwargs: Keyword arguments of any constant attributes for the function.

add_inputs

add_inputs(*args)

Add a sequence of inputs to the function invocation.

Args:

  • *args: List of inputs to be converted (should be Tf.Tensor).

Returns:

Wrapped inputs (identity standins that have additional metadata). These are also are also tf.Tensor's.

add_outputs

add_outputs(*args)

Add a sequence of outputs to the function invocation.

Args:

  • *args: List of outputs to be converted (should be tf.Tensor).

Returns:

Wrapped outputs (identity standins that have additional metadata). These are also tf.Tensor's.

Class Members

FUNCTION_INPUT_INDEX_ATTR

FUNCTION_NAME_ATTR

FUNCTION_OUTPUT_INDEX_ATTR

FUNCTION_UUID_ATTR

© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/contrib/lite/OpHint