espressif / esp-dl

Espressif deep-learning library for AIoT applications
MIT License
548 stars 118 forks source link

set_exponent() 这个指数应该如何设置? (AIV-416) #64

Closed xiao-mb closed 3 years ago

xiao-mb commented 3 years ago

把网络移植到s3上后,识别不正确。评估的准确率如下:

Evaluating the performance on esp32s3: accuracy of int16 model is: 0.996094 accuracy of fp32 model is: 0.996094 把同张图片导出,在PC上测试,识别正确。在S3上,不同的图片大多数会预测出同一个值,而且不正确。这个问题应该从哪些方面来定位原因?

Originally posted by @xiao-mb in https://github.com/espressif/esp-dl/issues/58#issuecomment-917624528

exponent的值原来为-8 改为-15,不同的图像,大部分会有不同的预测值,但是还是不对,猜测s3上的准确率不行可能与exponent这个值有关。所以这个值应该怎么设置? https://github.com/espressif/esp-dl/blob/dcaaa939edeef575a7340ff28dcfe8ff1411b988/tutorial/main/app_main.cpp#L314

训练模型用的数据集除了256,量化工具用的数据集也除了256,量化工具输出的指数为 -15 ,s3的像素点范围0-255。

yehangyang commented 3 years ago

训练模型用的数据集除了256,量化工具用的数据集也除了256,量化工具输出的指数为 -15 ,s3的像素点范围0-255。

@xiao-mb 如果训练时除了 256, 那么 input 的 exponent 设定为 -8。

PureHing commented 3 years ago

@yehangyang 这个我也很困惑。如果我采用8-bit量化,训练时数据img=img/255;那么对于esp32s3的预处理应该是如何?比如使用convert_to_u8.py得打unit8_t的数据img1,需要执行img1=round(img1/2552^|exponent|)吗 input.set_element((int8_t )img1).set_exponent(-8).set_shape({28, 28, 3}).set_auto_free(false);

yehangyang commented 3 years ago

@PureHing 从始至终只要保证 quant*2^exponent = float 。

如果训练的时候 img2_f=img1_f/255,img2_f 的取值范围是[0,1]。

对于上述的 int8_t 量化,其实有 1-bit 的精度损失。所以我建议,如果打算用 int8_t 量化的,

PureHing commented 3 years ago

@yehangyang thanks