Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

We should use relative comparing in testing model #1107

Open
tk26eng opened this issue Jun 21, 2020 · 2 comments
Open

We should use relative comparing in testing model #1107

tk26eng opened this issue Jun 21, 2020 · 2 comments
Assignees

Comments

@tk26eng
Copy link
Contributor

tk26eng commented Jun 21, 2020

static const T_FLOAT tolerance = 0.00001;
template<class T_IN, class T_RES>
inline bool same(T_IN input, T_RES result, T_IN& diff)
{
T_INT diff_ = input - T_IN(result);
diff = diff_;
return diff_ == 0;
}
template<>
inline bool same(T_FLOAT input, T_FLOAT result, T_FLOAT& diff)
{
T_FLOAT diff_ = std::abs(input - result);
diff = (tolerance > diff_) ? 0 : diff_;
return diff == 0;
}

In this above source, absolute error is used in comparing ground truth values and calculated values for elf binaries like lm_x86.elf. This comparison with absolute error works well when the values are normalized and range from 0.0 to 1.0.
But sometimes in some network, they are not normalized and range from 0 to 255 especially when output is image data. Then the absolute error of 0.00001 is too strict (small) for 32bit floating point which is valid within about 6 to 7 digit by decimal value.

Maybe, absolute error of 0.00001 is OK for lm_x86.elf because it doesn't use 32bit floating point.
But other elf binaries will use SIMD operations with 32bit floating point in some functions for faster calculation. So they might occur error of validation.

For example, the ground truth is 100.0 and calculated value is 100.000005, originally the test should pass. However, the comparison will fail because 32bit floating point has accuracy of 0.0001 (6digits of 100.0).

So we should use relative error for this problem.
This change from absolute error to relative one is very easy to modify. But this part has big effect to validation of model.

What do you think about changing absolute error to relative one ?

@tk26eng tk26eng self-assigned this Jun 21, 2020
@primenumber
Copy link
Contributor

We should consider both relative and absolute error, because of loss of significance...

@tk26eng
Copy link
Contributor Author

tk26eng commented Jun 23, 2020

@primenumber
How about using threshold like this ?

float val_gt; // ground truth
float val_calc; // calculated value
// Certain value is set to val_gt and val_calc here
abs_tol = 0.00001; // Same threshold as original code for smaller value
rel_tol = 0.00001; // 6 digits should be matched for bigger value
if(std::abs(val_calc - val_gt) < max(abs_tol, rel_tol * val_gt)){
  std::cout << "value is same" << std::endl;
}
else{
  std::cout << "value is different" << std::endl;
}

bo-mergebot bot pushed a commit that referenced this issue Sep 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants