This document is relevant for: Inf1
TensorFlow 2.x (tensorflow-neuron) analyze_model API#
Method#
tensorflow.neuron.analyze_model
Description#
Analyzes a keras.Model or a Python callable that can be decorated by
tf.function for it’s compatibility with Neuron. It displays supported
vs. unsupported operators in the model as well as percentages and counts of
each operator and returns a dictionary with operator statistics.
Arguments#
func: The
keras.Modelor function to be analyzed.example_inputs: A
tf.Tensoror a tuple/list/dict oftf.Tensorobjects for tracing the function. Whenexample_inputsis atf.Tensoror a list oftf.Tensorobjects, we expectfuncto have calling signaturefunc(example_inputs). Otherwise, the expectation is that inference onfuncis done by callingfunc(*example_inputs)whenexample_inputsis atuple, orfunc(**example_inputs)whenexample_inputsis adict. The case wherefuncaccepts mixed positional and keyword arguments is currently unsupported.
Returns#
A results
dictwith these keys: ``’percent_supported’, ‘supported_count’,
‘total_count’, ‘supported_operators’, ‘unsupported_operators’, ‘operators’, ‘operator_count’``.
Example Usage#
import tensorflow as tf
import tensorflow.neuron as tfn
input0 = tf.keras.layers.Input(3)
dense0 = tf.keras.layers.Dense(3)(input0)
model = tf.keras.Model(inputs=[input0], outputs=[dense0])
example_inputs = tf.random.uniform([1, 3])
results = tfn.analyze_model(model, example_inputs)
print(results)
# expected output
'''
BiasAdd
MatMul
100.00% of all operations (2 of 2) are supported
{'percent_supported': 100.0, 'supported_count': 2, 'total_count': 2,
'supported_operators': {'BiasAdd', 'MatMul'}, 'unsupported_operators': [],
'operators': ['BiasAdd', 'MatMul'], 'operator_count': {'MatMul': 1, 'BiasAdd': 1}}
'''
This document is relevant for: Inf1