AIMET Visualization for Quantization for TensorFlow API¶
Code Examples for Visualization of Weight tensors¶
Required imports
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import ResNet50
from aimet_tensorflow import plotting_utils
Visualizing weight ranges for layer
def visualizing_weight_ranges_for_single_layer():
# load a model
tf.keras.backend.clear_session()
_ = ResNet50(weights='imagenet', input_shape=(224, 224, 3))
sess = tf.compat.v1.keras.backend.get_session()
results_dir = 'artifacts'
with sess.as_default():
# Getting a layer for visualizaing its weight ranges
conv_op = sess.graph.get_operation_by_name('conv1_conv/Conv2D')
plotting_utils.visualize_weight_ranges_single_layer(sess=sess, layer=conv_op, results_dir=results_dir)
sess.close()
Visualizing Relative weight ranges for layer
def visualizing_relative_weight_ranges_for_single_layer():
# load a model
tf.keras.backend.clear_session()
_ = ResNet50(weights='imagenet', input_shape=(224, 224, 3))
sess = tf.compat.v1.keras.backend.get_session()
results_dir = 'artifacts'
with sess.as_default():
# Getting a layer for visualizaing its weight ranges
conv_op = sess.graph.get_operation_by_name('conv1_conv/Conv2D')
plotting_utils.visualize_relative_weight_ranges_single_layer(sess=sess, layer=conv_op,
results_dir=results_dir)
sess.close()