cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer
Observer
142 Views
Registered: ‎09-10-2018

customized input_fn.py for decent_q

I am trying to quantize a CNN network from tensorflow and I am dealing with sensor data, my input data are not images.

I stored the calibration data in NumPy array and I want to feed it to the quantizer with the input_fn.py function but I am confused, how the calib_input function works. This is my decent_q.sh:

decent_q quantize \
--input_frozen_graph frozen_graph.pb \
--input_nodes input \
--input_shapes ?,20,60,1 \
--output_nodes O \
--input_fn input_fn.calib_input \
--method 1 \
--gpu 0 \
--calib_iter 64 \
--output_dir ./quantize_results \

and this is my input_fn.py:

import numpy as np

def calib_input(iter):
data=np.load("./calibration_data/inputs.npy")

inputs = np.expand_dims(data, axis=3) # so the shape of the data is now equal 64 * 20 * 60 * 1

return {"input": inputs}

 

I get the following error:

 

File "/home/mehdi/anaconda2/envs/decent/lib/python3.6/site-packages/tensorflow/contrib/decent_q/python/utils.py", line 126, in gen_feed_dict
"key {} not found, please check your input_fn.".format(name))
ValueError: key I not found, please check your input_fn.

 

What is exactly key I ?

1 Reply
Highlighted
Observer
Observer
91 Views
Registered: ‎09-10-2018

Re: customized input_fn.py for decent_q

I solved the error.

Actually my frozen graph has some pre-processing that I needed to skip when quantizing. The input of my frozen graph is named "I" (thus the error Key I not found) and the input of the part I want to quantize starts with "input".

Even if the decent_q script needs the input of the part that will be quantized (in this case --input_nodes input ), the input_fn.py must return the data that is fed to the input "I" of the whole graph so input_fn.py should look like:

def calib_input(iter):
#load the data before prerocessing to I
return {"I": inputs}

 

0 Kudos