This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA2: TIDL Host emulation tool convolution output issues

Part Number: TDA2


Issue with the convolutional output in the function : TIDL_refConv2d_i8u_032s_cn in tidl_conv2d_base.c

First, the test setup:


A simple convolutional network with 3x3 kernel and bias with 2 output channels. The first kernel has all zeros and the second kernel has all ones. Bias for first channel is 1 and second channel is 2.

Now all the variables involved:

input raw rgb = 255 (all 1s)
inQuantFactor = 65280
weightsQ = 65536
biasQ = 4194304
biasQFact = 255
rgb size input = 3x3x3
num of output channels = 2

In foating point:
input = 1.0
weights = [0, 1] (1st kernel all weights are zero, and second kernel all weights are 1)
bias = [ 1, 2]

The convolved output of the first channel should be 1.  Just bias, because all weights are zero.
The convolved output of the second channel should be : 1.0 * (3x3x3) *1 + 2 = 29.

Ti fixed point: 

weights having values[0,1] becomes approximately: [0,1]*weightsQ/255 = [0, 255].

biases [1, 2] becomes approximately: [1, 2]*biasQ/255 = [16384,32767].

Now checking  the convolution in TIDL_refConv2d_i8u_032s_cn function:

There,

pInChannel contains inputs which is uint8, and all the values are 255.

Bias is multiplied by the biasQFact (255). I understand this is because of the inQuantFactor, and the bias needs to be scaled.

convolution happens as: input * weights + bias*biasQFact

for first channel,  output is = bias*biasQFact = 4177920
for second channel: 255* (3*3*3)*255 + 32767*255 = 10111260

So floating point 1 is represented as 4177920 and 29 is represented as 10111260 which is wrong.

Since the bias and weights are not represented by the same Q factor, the output will match only when
the input also has a QFactor, 

With inout Q factor, second channel should be: 255*64 * (3*3*3)*255 + 32767*255 = 120718785, which should be the output.

What am i missing here?

I have attached the model and inputs to reproduce this problem.

ti.zip

  • Hi Vijay,

    Please refer to below e2e thread, where we had one simple cifar net example to understand the tidl layers. I would recommend to start with this to better understand the input,weights and output Q formats. Then on top of it you try your experiments to get the better results.

    e2e.ti.com/.../689876

    Thanks,
    Praveen
  • Hi Praveen,

     The above example is created in such a way that one can figure out what the issue is without doing into the code to debug.

     Anyway, I went and fixed the TIDL_importQuantLayerParams  function in tidl_tfimport.cpp to make the above toy example work. The issue arises when the min - max range of weights and bias are not same.

      By the way, the cifar net example also didnt match (TIDL .01.01). I loaded the model shared in the above link and obtained outputs from each of the layers to compare with the host emulation output. Outputs doesnt match. I have attached all the tools required to reproduce the issue, in case you guys want to try it.

    tidl_keras_example.zip

  • Hi Vijay,

    Thanks for pointing this. I am closing this thread as you could fix the issue and you can feel free to open this thread or create a new thread if you face any issues.

    Regards,
    Praveen