AIMET Visualization for Quantization for TensorFlow API

Top-level API for Visualization of Weight tensors

aimet_tensorflow.plotting_utils.visualize_weight_ranges_single_layer(sess, layer, visualization_url)

Given a layer, visualizes weight ranges with scatter plots and line plots

Parameters
  • sess – tf.compat.v1.Session

  • layer – layer with weights

  • visualization_url – user inputted url with session id set as optimization for the visualizations

Returns

bokeh_session, so that user can close the session


aimet_tensorflow.plotting_utils.visualize_relative_weight_ranges_single_layer(sess, layer, visualization_url)

Publishes a line plot showing weight ranges for each layer, summary statistics for relative weight ranges, and a histogram showing weight ranges of output channels

Parameters
  • sess – tf.compat.v1.Session

  • layer – layer with weights

  • visualization_url – user inputted url with session id set as optimization for the visualizations

Returns

bokeh_session, so that user can close the session


Code Examples for Visualization of Weight tensors

Required imports

# TF specific imports
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import ResNet50

# Import for starting Bokeh Server
from aimet_common.utils import start_bokeh_server_session
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()

    with sess.as_default():
        # Getting a layer for visualizaing its weight ranges
        conv_op = sess.graph.get_operation_by_name('conv1_conv/Conv2D')

        # Starting a Bokeh Server with port number 8001
        visualization_url = start_bokeh_server_session(port=8001)
        plotting_utils.visualize_weight_ranges_single_layer(sess=sess, layer=conv_op,
                                                            visualization_url=visualization_url)
    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()

    with sess.as_default():
        # Getting a layer for visualizaing its weight ranges
        conv_op = sess.graph.get_operation_by_name('conv1_conv/Conv2D')

        # Starting a Bokeh Server with port number 8001
        visualization_url = start_bokeh_server_session(port=8001)
        plotting_utils.visualize_relative_weight_ranges_single_layer(sess=sess, layer=conv_op,
                                                                     visualization_url=visualization_url)
    sess.close()