UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer lzhao
Observer
675 Views
Registered: ‎07-17-2019

decent error

Jump to solution

 

Once I run the decent script, I got following error. Any suggestion? Thanks!

#####################################
QUANTIZE
#####################################
Traceback (most recent call last):
File "/harddisk1/liangzhao/anaconda2/envs/decent/bin/decent_q", line 10, in <module>
sys.exit(run_main())
File "/harddisk1/liangzhao/anaconda2/envs/decent/lib/python2.7/site-packages/tensorflow/contrib/decent_q/python/decent_q.py", line 540, in run_main
app.run(main=my_main, argv=[sys.argv[0]] + unparsed)
File "/harddisk1/liangzhao/anaconda2/envs/decent/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/harddisk1/liangzhao/anaconda2/envs/decent/lib/python2.7/site-packages/tensorflow/contrib/decent_q/python/decent_q.py", line 539, in <lambda>
my_main = lambda unused_args: main(unused_args, FLAGS)
File "/harddisk1/liangzhao/anaconda2/envs/decent/lib/python2.7/site-packages/tensorflow/contrib/decent_q/python/decent_q.py", line 332, in main
input_fn = _parse_input_fn(flags.input_fn)
File "/harddisk1/liangzhao/anaconda2/envs/decent/lib/python2.7/site-packages/tensorflow/contrib/decent_q/python/decent_q.py", line 114, in _parse_input_fn
raise ValueError('Fail to import input_fn, error: ', e)
ValueError: ('Fail to import input_fn, error: ', ImportError('No module named default',))
decent.sh: 27: decent.sh: --gpu: not found
#####################################
QUANTIZATION COMPLETED
#####################################

 

Installed packages:

DNNDK version: 3.1

tensoflow(1.12.0) and tensorflow-gpu(1.9.0) installed.

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
583 Views
Registered: ‎03-27-2013

回复: decent error

Jump to solution

Hi @lzhao ,

 

Thanks for your response. The input_fn function is more like a data preprocessing function.

In my opinion the python function is used to transfer original data into the format of ConvNet input.

I am afraid that I can't find a public reference contain the whole flow from training to deployment. I would just take my simple test ConvNet as example.

During training I use the X/y dataset I have stored into npy file, just do the normalization and feed them into the ConvNet:

X = np.load("features.npy")

y = np.load("label.npy")

# Normalization
X = X / 255.0

...


model.fit(X, y, epochs=10)

So when I trying to quantize this model I need to do the same to the calibration data, that is the input_fn function noticed that only X(features) data is need:

def calib_input(iter):
X = np.load("features.npy") / 255.0
images = X[:100]
return {"conv2d_input": images}

The point is that you just do the same to preprocess the data for both model training and quantization calibaration so that the Convnet can just get the same format of data input.

Hope this can help and please feel free to let me know if I have missed anything here. :-)

 

 

 

Best Regards,
Jason
-----------------------------------------------------------------------------------------------
Please mark the Answer as "Accept as solution" if the information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
-----------------------------------------------------------------------------------------------

View solution in original post

10 Replies
Xilinx Employee
Xilinx Employee
633 Views
Registered: ‎03-27-2013

回复: decent error

Jump to solution

Seems like you are using "default" as input to --input_fn.

For common usage I would suggest you to use the real pre-processing function as input.

Please refer to DNNDK model examples under DNNDK install location.

e.g. for resnet50 tensorflow example you can find it here:

xilinx_dnndk_v3.1/host_x86/models/tensorflow/resnet_v1_50/decent_q.sh

The input python function can be founded at xilinx_dnndk_v3.1/host_x86/models/tensorflow/resnet_v1_50/resnet_v1_50_input_fn.py which handle the data(image) preprocessing.

Best Regards,
Jason
-----------------------------------------------------------------------------------------------
Please mark the Answer as "Accept as solution" if the information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
-----------------------------------------------------------------------------------------------
Observer lzhao
Observer
604 Views
Registered: ‎07-17-2019

回复: decent error

Jump to solution

Hi Jason,

Really appreciated your response.

Actually I did referenced resnet50 tensorflow example as you mentioned. Also the examples on github, https://github.com/Xilinx/Edge-AI-Platform-Tutorials/blob/master/docs/MNIST_tf/graph_input_fn.py

It's still unclear to me on how to write this input_fn. Quote from DNNDK_User_Guide(UG1327 v1.6 August 13, 2019): 

decent_input_fn.png

From my point of view, the explaination and instruction of creating of input_fn is still kind vague. What's the purpose of this input_fn? What exactly need to be done in this input_fn? What happened if the data is not images? In my case, my input data is matrices. 

Thank you!

 

Best,

Liang

Tags (2)
0 Kudos
Xilinx Employee
Xilinx Employee
584 Views
Registered: ‎03-27-2013

回复: decent error

Jump to solution

Hi @lzhao ,

 

Thanks for your response. The input_fn function is more like a data preprocessing function.

In my opinion the python function is used to transfer original data into the format of ConvNet input.

I am afraid that I can't find a public reference contain the whole flow from training to deployment. I would just take my simple test ConvNet as example.

During training I use the X/y dataset I have stored into npy file, just do the normalization and feed them into the ConvNet:

X = np.load("features.npy")

y = np.load("label.npy")

# Normalization
X = X / 255.0

...


model.fit(X, y, epochs=10)

So when I trying to quantize this model I need to do the same to the calibration data, that is the input_fn function noticed that only X(features) data is need:

def calib_input(iter):
X = np.load("features.npy") / 255.0
images = X[:100]
return {"conv2d_input": images}

The point is that you just do the same to preprocess the data for both model training and quantization calibaration so that the Convnet can just get the same format of data input.

Hope this can help and please feel free to let me know if I have missed anything here. :-)

 

 

 

Best Regards,
Jason
-----------------------------------------------------------------------------------------------
Please mark the Answer as "Accept as solution" if the information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
-----------------------------------------------------------------------------------------------

View solution in original post

Xilinx Employee
Xilinx Employee
545 Views
Registered: ‎11-29-2007

Re: decent error

Jump to solution

Originally, this Resnet50 for Tensorflow was trained without scaling the images to 0-1.

The readme file in tf_resnet50 from Model Zoo says:

  1. data channel order: RGB(0~255)                 
  2. resize: short side reisze to 256 and keep the aspect ratio.
  3. center crop: 224 * 224
  4. input = input - [123.68, 116.78, 103.94]

Thus, also the input function and the main.cc files should agree with the same pre-processing method.

I attached an input function as example.

Observer lzhao
Observer
507 Views
Registered: ‎07-17-2019

Re: decent error

Jump to solution
Thank you for the explanation.
0 Kudos
Observer lzhao
Observer
458 Views
Registered: ‎07-17-2019

回复: decent error

Jump to solution

Hi Jason,

Really appreciate your help. It make a lot more sense to me now.

I've added an input function, but I am still getting an error message:

#####################################
QUANTIZE
#####################################
Traceback (most recent call last):
  File "/harddisk1/xxxx/anaconda2/envs/decent/bin/decent_q", line 10, in <module>
    sys.exit(run_main())
  File "/harddisk1/xxxx/anaconda2/envs/decent/lib/python2.7/site-packages/tensorflow/contrib/decent_q/python/decent_q.py", line 537, in run_main
    raise ValueError("Unknown arguments: ", unparsed)
ValueError: ('Unknown arguments: ', [' '])
#####################################
QUANTIZATION COMPLETED
#####################################

 

In the original python project, the data preprocessing function is using generator instead of return, like below:

 

class My_Generator():
    def __init__(self, in_dir, batch_size, data_shape, output='image'):
        self.path = in_dir
        self.cached_data = {}
        self.file_list = glob.glob(in_dir + "/*")
        self.batch_size = batch_size
        self.ratio = 1024 / data_shape[0]
        self.data_shape = data_shape
        self.output = output

    def Generator(self):
        ...
            yield batch_in, batch_out

And then during the train, the generator will be taken as an input.

 

 

mygen_image = My_Generator("Data", batch_size=batch_size, data_shape=data_shape, output='image')
model.fit_generator(mygen_image.Generator(), epochs=epochs, steps_per_epoch=80, verbose=1, callbacks=unet_callbacks)

 

So, in my input function calib_input(), yield was used instead of return. Is this could be a issue?

Second, the project is based on keras, is this also be an issue? Thanks!

 

Best,

Liang

 

 

0 Kudos
Xilinx Employee
Xilinx Employee
425 Views
Registered: ‎03-27-2013

回复: decent error

Jump to solution

Hi @lzhao ,

 

Would you please provide more detailed information about the quantization?

Like the whole command, and the files you are using.

Best Regards,
Jason
-----------------------------------------------------------------------------------------------
Please mark the Answer as "Accept as solution" if the information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
-----------------------------------------------------------------------------------------------
0 Kudos
Highlighted
Observer lzhao
Observer
398 Views
Registered: ‎07-17-2019

回复: decent error

Jump to solution

Hi Jason,

Following is the shell script file.

#ctivate DECENT_Q Python3.6 virtual environment
conda activate decent_q

# generate calibraion images and list file
#python generate_images.py

# remove existing files
#rm -rf ./quantize_results


# run quantization
echo "#####################################"
echo "QUANTIZE"
echo "#####################################"
decent_q quantize \
  --input_frozen_graph ./noise_filter_model/Unet.pb \
  --input_nodes input_1 \
  --input_shapes ?,1024,1024,6 \
  --output_nodes conv2d_23/Sigmoid \
  --method 1 \
  --input_fn unet_input_fn.calib_input \
  #--calib_iter 100 \
  #--batch_size 50 \
  #--image_dir ./calib_dir \
  #--image_list ./calib_dir/calib_list.txt \
  #--scales 0.00392,0.00392,0.00392 \
  #--gpu 0

echo "#####################################"
echo "QUANTIZATION COMPLETED"
echo "#####################################"

Below is the input function file.

import glob
import time
import numpy as np
from scipy.ndimage import zoom
from skimage.measure import block_reduce
from scipy import sparse as sp
import keras
from keras.backend.tensorflow_backend import set_session


width = 1024
data_shape=(width, width, 6)
batch_size = 1
in_dir = "smallDataset"

path = in_dir
cached_data = {}
file_list = glob.glob(in_dir + "/*")
#batch_size = batch_size
ratio = 1024 / data_shape[0]
#data_shape = data_shape
output = output

def calib_input(iter):
    np.random.shuffle(file_list)
    batch_in = np.zeros((batch_size,) + data_shape)

    if output == 'image':
        batch_out = np.zeros((batch_size,) + data_shape)
    elif output == 'label':
        batch_out = np.zeros(batch_size)

    for i in range(len(file_list)):
        with open(file_list[i], "rb") as f:
            data = pickle.load(f)
            max_reduce(data)
            cached_data[file_list[i]] = data

    while True:
        for i in range(batch_size):
            f_ind = np.random.randint(0, len(file_list))
            #if os.path.basename(self.file_list[f_ind]) in self.cached_data:
            #    data = self.cached_data[self.file_list[f_ind]]
            #else:
            #    with open(self.file_list[f_ind], "rb") as f:
            #        data = pickle.load(f)
            #        self.max_reduce(data)
            #        self.cached_data[self.file_list[f_ind]] = data
            data = cached_data[file_list[f_ind]]
            ind = np.random.randint(0, len(data))

            #train_data = map(lambda x: block_reduce(x.toarray(), block_size=(self.ratio,self.ratio), func=np.max), data[ind].hL)
            train_data = data[ind].train
            #train_data = np.swapaxes(train_data, 0, 2)
            batch_in[i] = np.heaviside(train_data, 0)

            if output == 'image':
                #gt_data = map(lambda x: block_reduce(x.toarray(), block_size=(self.ratio,self.ratio), func=np.max), data[ind].gthL)
                gt_data = data[ind].image
                #gt_data = np.swapaxes(gt_data, 0, 2)
            elif output == 'label':
                gt_data = np.array(data[ind].label)
            batch_out[i] = np.heaviside(gt_data, 0)

        yield batch_in, batch_out


def max_reduce(data):
        for d in range(len(data)):
            data[d].train = map(lambda x: block_reduce(x.toarray(), block_size=(ratio,ratio), func=np.max), data[d].hL)
            data[d].image = map(lambda x: block_reduce(x.toarray(), block_size=(ratio,ratio), func=np.max), data[d].gthL)
            data[d].train = np.swapaxes(data[d].train, 0, 2)
            data[d].image = np.swapaxes(data[d].image, 0, 2)

Really apprecate your help!

Best,

Liang

0 Kudos
Xilinx Employee
Xilinx Employee
383 Views
Registered: ‎03-27-2013

回复: decent error

Jump to solution

Hi @lzhao ,

 

To my understanding the function should return a dictionary like: {<input_node_name>: input_data_array}, look at Xilinx resnet50 examples which Giovanni mentioned and my simple one.

But I am afraid that I can't see that structure in your calib_input function. And I would not use "yield" instead of "return". Just modify one thing at a time or you may meet a complex issue here.

And BTW you would need to do all the preprocess operations in both quantization calibration and depoyment(MPSoC) so I would suggest you to check if you can simplify your calib_input code.

Best Regards,
Jason
-----------------------------------------------------------------------------------------------
Please mark the Answer as "Accept as solution" if the information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
-----------------------------------------------------------------------------------------------
Observer lzhao
Observer
295 Views
Registered: ‎07-17-2019

回复: decent error

Jump to solution

Hi Jason,

Thanks for all the reply.

For some reason, I put a space after the backslash, and that cause the 'Unknown arguments: ' error.

--input_fn some_input_fn.calib_input \ 

Stupid mistake, but lesson learned.

Again thanks for being patient answering all my questions!

 

Regards,

Liang

0 Kudos