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, results_dir)

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

Parameters
  • sess – tf.compat.v1.Session

  • layer – layer with weights

  • results_dir – Directory to save the Bokeh plots

Returns

Bokeh plot


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

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

  • results_dir – Directory to save the Bokeh plots

Returns

bokeh plot


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()