quantize_preprocess

Function Usage

Preprocesses the quantization of a graph based on the quantization configuration file (currently, only balanced quantization is supported), inserts the balanced quantization operator, and generates a balance factor record file record_file that is to be read in the subsequent quantize_model phase.

Prototype

quantized_preprocess(graph, config_file, record_file, outputs=None)

Command-Line Options

Option

Input/Return

Meaning

Restriction

graph

Input

A tf.Graph of the model to be quantized.

A tf.Graph.

config_file

Input

User-defined quantization configuration file, which specifies the configuration of each layer to be quantized in the tf.Graph.

A string

record_file

Input

Directory of the balance factor record file, including the file name.

A string

outputs

Input

List of output nodes of the graph.

When the output nodes change due to graph modification, this list is updated accordingly.

A list.

Default: None

Outputs

None.

Examples

1
2
3
4
5
6
7
8
9
import amct_tensorflow as amct
# Build a network to be quantized.
network = build_network()

# Insert the quantization API.
amct.quantized_preprocess(
      graph=tf.get_default_graph(),
      config_file="./configs/config.json",
      record_file="./record_scale_offset.txt")