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.

Compiler/PROCESSOR-SDK-DRA8X-TDA4X: caffe scale layer with negative weight

Part Number: PROCESSOR-SDK-DRA8X-TDA4X

Tool/software: TI C/C++ Compiler

hi.

I want to use scale layer with caffe  like this:

layer {
  name: "test"
  type: "Scale"
  bottom: "bot"
  top: "top"
  param { lr_mult: 0.0 decay_mult: 0.0 }
  scale_param {
    filler { type: "constant" value: -1.0 }
    bias_term: false
  }
}

but the result is different form my expectation.

I found tidlModleImport use FLT_MIN (1.175494351E-38) as the minimum value of float type to determine the range and maximum value of a parameter for batchnorm,  (tidl_import_common.cpp)

In this code, I think it doesn't work properly if all the input data has a negative value.

How to use scale layer with negative weights?

Thanks

  •   float min = FLT_MAX;
      float max = FLT_MIN;
      int32_t i;
      for (i = 0; i < dataSize; i++)
      {
        min = ((data[i] ) < min) ? (data[i] ) : min;
        max = ((data[i] ) > max) ? (data[i]) : max;
      }
    Actually  FLT_MAX is initialized to min and will be updated with -1 for your case. I dod not see any issue with this code.
    Can you share the min and "quantPrec" values used for you case to re-produce this issue 
  • Hi, Kumar.
    In my case the initial value of "max" is positive, so the variable "max" remains FLT_MIN.
    inputs:
    data = -1, -1, -1, -1
    dataSize = 4
    weightsElementSizeInBits = 8
    TIDL_findRange(data, dataSize, &min, &max, 1.0); [line 4517]
    min : -1,
    max: 1.17549435e-38
    TIDL_QuantizeSignedMax((int8_t *)params, data, dataSize, min, max, weightsElementSizeInBits) [line 4522]
    quantPrec : 128
    params : 128, 128, 128, 128
    Regards.
  • Since the quantPrec is 128, I am expecting the params to -128, -128, -128, -128 with the below code.

    param = (pData *  quantPrec - QUAN_STYLE2_ROUND);

    Can you check, How are you getting128?

    BTW, set  max = -FLT_MIN; in TIDL_findRange to get max -1. But I do not think this solve the problem that you are observing

  • Sorry. There is a typo.

    The parameters are -128, -128, -128, -128.

    Does "TIDL_BatchNormLayer" work as follows? (Used as "scale layer")

    out = in * param (-128) / weightScale (128)