Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quantize all nodes except a particular one?

Tags:

tensorflow

I am using tensorflow Graph Transform Tool to quantize the graph using

input_names = ["prefix/input"]
output_names = ["final_result"]


transforms1 = ["strip_unused_nodes","fold_constants(ignore_errors=true)",  "fold_batch_norms",  "fold_old_batch_norms","quantize_weights" ]

transformed_graph_def = TransformGraph(graph.as_graph_def(), input_names,output_names, transforms1)

I use the option quantize_weights to quantize the weights in graph, I know that certain nodes can remain unquantized by changing threshold minimum_size in quantize_weights, so leaving some nodes unquantized is certainly possible.

I want to quantize the weights of all nodes except a particular node with the name K or a set of nodes that have a name in K(set). How can this be achieved?

like image 878
A. Sam Avatar asked Sep 01 '25 17:09

A. Sam


1 Answers

EDIT: the previous answer refered to Tensorflow Lite code. I updated it to refer to Tensorflow.

Looking at the implementation of Tensorflow's quantize_weights, these are the instances where weights don't get quantized:

  1. tensor that is not type float
  2. tensor that has fewer than 1024 weights (or another number specified by the parameter minimum_size)

If you are able to modify nodes in the graph so that they are excluded by one of the above rules, then quantize, then revert the nodes to the pre-quantized state, you might be able to do this.

like image 187
Yuval Avatar answered Sep 07 '25 03:09

Yuval