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: 
Highlighted
1,198 Views
Registered: ‎03-04-2018

Quantize issue in ml-suite for caffe

Jump to solution

I cloned recent ml-suite and try to use api quantize.pyc. I use this code for a try.

 

MLSUITE_ROOT=/ml-suite

 

for BITWIDTH in 16 8; do
    python $MLSUITE_ROOT/xfdnn/tools/quantize/quantize.py \
        --deploy_model $MLSUITE_ROOT/models/caffe/resnet/fp32/resnet50_without_bn_deploy.prototxt \
        --output_json $MLSUITE_ROOT/examples/quantize/work/caffe/resnet/resnet50_without_bn_quantized_int${BITWIDTH}_deploy.json \
        --weights $MLSUITE_ROOT/models/caffe/resnet/fp32/resnet50_without_bn.caffemodel \
        --calibration_directory $MLSUITE_ROOT/models/data/ilsvrc12/ilsvrc12_img_cal \
        --calibration_size 32 \
        --bitwidths ${BITWIDTH},${BITWIDTH},${BITWIDTH} \
        --dims 3,224,224 \
        --transpose 2,0,1 \
        --channel_swap 2,1,0 \
        --raw_scale 255.0 \
        --mean_value 104.0,117.0,123.0 \
        --input_scale 1.0

 

This step is throwing error as follow:

 
Processing layer 0 of 139
Layer Name:input Type:Input
('Inputs:', '[], Outputs:', "['data']")
Quantizing layer output...
('Min: ', 0, ', Max: ', 151.0)
('n: ', 128, ', len(bin_edges): ', 2196)
('Mean : th_layer_out: ', 151.03439635535307, ', sf_layer_out: ', 1.1892472153964808)
('bw_layer_out: ', 8)
('th_layer_out: ', 151.03439635535307)
--------------------------------------------------------------------------------
Processing layer 1 of 139
Layer Name:conv1 Type:Convolution
('Inputs:', "['data'], Outputs:", "['conv1']")
('Quantizing conv input layer ...', 'conv1')
Traceback (most recent call last):
  File "/home/local/ZOHOCORP/durga-7043/ml-suite/xfdnn/tools/quantize/quantize.py", line 207, in <module>
    quantizer.quantize()
  File "/home/local/ZOHOCORP/durga-7043/ml-suite/xfdnn/tools/quantize/quantize.py", line 96, in quantize
    quant_layers = caffeObj.executeCalibration(bitwidths, self.deploy_model, quant_params)
  File "./xfdnn/tools/quantize/quantize_caffe.py", line 101, in executeCalibration
  File "./xfdnn/tools/quantize/quantize_caffe.py", line 213, in preProcess
KeyError: 'data'

 

For clear description of above error please go through the following txt file

0 Kudos
1 Solution

Accepted Solutions
Visitor sairahul321
Visitor
1,164 Views
Registered: ‎10-09-2018

Re: Quantize issue in ml-suite for caffe

Jump to solution

I have similar issue with the resnet101 and resnet152 model, but my resnet50 model quantized fine. 

 

resnet101-->

 

Processing layer 0 of 483

Layer Name:input Type:Input

Inputs: [], Outputs: ['data']

Quantizing layer output...

Min:  0 , Max:  151.0

n:  128 , len(bin_edges):  1099

Mean : th_layer_out:  151.06876138433515 , sf_layer_out:  1.1895178061758673

bw_layer_out:  8

th_layer_out:  151.06876138433515

--------------------------------------------------------------------------------

Processing layer 1 of 483

Layer Name:conv1 Type:Convolution

Inputs: ['data'], Outputs: ['conv1']

Quantizing conv input layer ... conv1

Traceback (most recent call last):

  File "./xfdnn/tools/quantize/quantize.py", line 239, in <module>

  File "./xfdnn/tools/quantize/quantize.py", line 157, in quantize

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 110, in executeCalibration

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 222, in preProcess

KeyError: 'data'

 

resnet152-->

 

Processing layer 0 of 721

Layer Name:input Type:Input

Inputs: [], Outputs: ['data']

Quantizing layer output...

Min:  0 , Max:  151.0

n:  128 , len(bin_edges):  2196

Mean : th_layer_out:  151.03439635535307 , sf_layer_out:  1.1892472153964808

bw_layer_out:  8

th_layer_out:  151.03439635535307

--------------------------------------------------------------------------------

Processing layer 1 of 721

Layer Name:conv1 Type:Convolution

Inputs: ['data'], Outputs: ['conv1']

Quantizing conv input layer ... conv1

Traceback (most recent call last):

  File "./xfdnn/tools/quantize/quantize.py", line 239, in <module>

  File "./xfdnn/tools/quantize/quantize.py", line 157, in quantize

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 110, in executeCalibration

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 222, in preProcess

KeyError: 'data'

0 Kudos
5 Replies
Visitor sairahul321
Visitor
1,165 Views
Registered: ‎10-09-2018

Re: Quantize issue in ml-suite for caffe

Jump to solution

I have similar issue with the resnet101 and resnet152 model, but my resnet50 model quantized fine. 

 

resnet101-->

 

Processing layer 0 of 483

Layer Name:input Type:Input

Inputs: [], Outputs: ['data']

Quantizing layer output...

Min:  0 , Max:  151.0

n:  128 , len(bin_edges):  1099

Mean : th_layer_out:  151.06876138433515 , sf_layer_out:  1.1895178061758673

bw_layer_out:  8

th_layer_out:  151.06876138433515

--------------------------------------------------------------------------------

Processing layer 1 of 483

Layer Name:conv1 Type:Convolution

Inputs: ['data'], Outputs: ['conv1']

Quantizing conv input layer ... conv1

Traceback (most recent call last):

  File "./xfdnn/tools/quantize/quantize.py", line 239, in <module>

  File "./xfdnn/tools/quantize/quantize.py", line 157, in quantize

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 110, in executeCalibration

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 222, in preProcess

KeyError: 'data'

 

resnet152-->

 

Processing layer 0 of 721

Layer Name:input Type:Input

Inputs: [], Outputs: ['data']

Quantizing layer output...

Min:  0 , Max:  151.0

n:  128 , len(bin_edges):  2196

Mean : th_layer_out:  151.03439635535307 , sf_layer_out:  1.1892472153964808

bw_layer_out:  8

th_layer_out:  151.03439635535307

--------------------------------------------------------------------------------

Processing layer 1 of 721

Layer Name:conv1 Type:Convolution

Inputs: ['data'], Outputs: ['conv1']

Quantizing conv input layer ... conv1

Traceback (most recent call last):

  File "./xfdnn/tools/quantize/quantize.py", line 239, in <module>

  File "./xfdnn/tools/quantize/quantize.py", line 157, in quantize

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 110, in executeCalibration

  File "./xfdnn/tools/quantize/quantize_caffe.py", line 222, in preProcess

KeyError: 'data'

0 Kudos
Visitor sairahul321
Visitor
1,158 Views
Registered: ‎10-09-2018

Re: Quantize issue in ml-suite for caffe

Jump to solution

I think I might have found the solution to my resnet 101 and 152 issue. I compared working resnet 50 prototxt file with 101 and 152 models and found the input layer is represented differently. Once I made the change quantization is working fine.

 

Working setup

layer {

  name: "data"

  type: "Input"

  top: "data"

  input_param {

    shape {

      dim: 1

      dim: 3

      dim: 224

      dim: 224

    }

  }

}

 

By default it came like this

 

name: "ResNet-101"

input: "data"

input_dim: 1

input_dim: 3

input_dim: 224

input_dim: 224

0 Kudos
Xilinx Employee
Xilinx Employee
1,140 Views
Registered: ‎09-11-2014

Re: Quantize issue in ml-suite for caffe

Jump to solution
Thanks for the question and the follow up. The v1.1 caffe quantizer does have a strict requirement that the input layer be named “data”. This error happens when the caffe layers are loaded, and the quantizer looks for the dimension of the data layer, and can’t find “data”. This has been enhanced in ml-suite v1.2 which is now on the master branch.
1,131 Views
Registered: ‎03-04-2018

Re: Quantize issue in ml-suite for caffe

Jump to solution

Thank you for reply, it's working now.

0 Kudos
Visitor zohoraja
Visitor
863 Views
Registered: ‎10-12-2018

Re: Quantize issue in ml-suite for caffe

Jump to solution

Hi Bryanloz,

 We would like to stay with 1.1 because we use VCU1525 (on premises). Moving to 1.2 requires couple of changes in the repo which is difficult to manage at our end. Hence, please let us know how we can change the name of input layer to 'data'. 

Also, the repo has only .pyc  files not .py for  compile/quantizer . Please let us know the source files for the same. It would be easier for us extend/customise for our use. We have no plans to outsource or external use. It is solely for internal purposes only.

Regards,
Raja

 

0 Kudos