armnn icon indicating copy to clipboard operation
armnn copied to clipboard

Noisy inference results with TF2 int8 tflite models

Open Rahn80643 opened this issue 2 years ago • 8 comments

Hi,

I'm migrating our segmentation model from TensorFlow1 to TensorFlow2, and the model is retrained with TensorFlow quantization aware training technique; however, the inference results of TF2 tflite model from ArmNN are not ideal, the comparisons and environment settings are shown below:

armnn2202_1

armnn2202_2

  • ArmNN 22.02
  • Compute Library 22.02
  • FlatBuffers 1.12.0
  • Protobuf 3.12.0
  • TensorFlow 2.4.0

Based on the inference results from TensorFlow tflite API, the weights in tflite models seems normal, but the inference results from ArmNN contain many noisy pixels, I want to ask:

  1. Is this issue resulted from the version of TensorFlow or tflite?
  2. How to effectively improve the inference results in ArmNN?

Best Regards, Rahn

Rahn80643 avatar Apr 25 '22 05:04 Rahn80643

Hi @Rahn80643,

thank you very much for your comment. which backend are you using when you run ArmNN, CpuAcc, GpuAcc or CpuRef?

TeresaARM avatar Apr 25 '22 10:04 TeresaARM

Hi @TeresaARM,

I've tested with CpuAcc and GpuAcc backend, and the inference results are similar

Rahn80643 avatar Apr 26 '22 01:04 Rahn80643

Hi @Rahn80643,

could you give it a go to CpuRef? and see if the results are closer to TensorFlow? The performance will be worse than CpuAcc and GpuAcc, as CpuRef is just a "reference", but this information will help us to find out where the issue is.

Thank you!

TeresaARM avatar Apr 26 '22 09:04 TeresaARM

Hi @TeresaARM,

The followings are the inference results using CpuRef, and the results are not closer to those from TensorFlow

armnn2202_1

armnn2202_2

Thank you

Rahn80643 avatar Apr 27 '22 03:04 Rahn80643

Hi,

I compared two int8 tflite models trained in TensorFlow1 and TensorFlow2 respectively, and I found the input zero point values are different. Is this the main reason why inferring TensorFlow2 int8 tflite model generates noisy results? If so, how to include the input zero point into ArmNN inference code to solve this issue?

zero_point

Rahn

Rahn80643 avatar May 13 '22 08:05 Rahn80643

yes, this could be the problem. In your application code, when you convert the input image into a tensor for Arm NN, are you taking the zero-point into account?

MatthewARM avatar May 13 '22 08:05 MatthewARM

If this is the problem, there is some good explanation of it here: https://github.com/ARM-software/armnn/issues/161

MatthewARM avatar May 13 '22 08:05 MatthewARM

Hi,

I've tried the following modifications but the inference results still contain noisy results:

  1. Based on thread #161, the author had tried not to do preprocess the image and divide the output by 255. I tried the same process in ArmNN; however, since the values of output results are within the range of [0, 255], if the values are divided by 255, the results will be all 0s.

  2. the input images are preprocessed based on the following formula in ArmNN, new_value = ((old_value/scale_factor) - mean)/ stddev. Therefore, I've tried changing mean values, but the inference results still contain noisy results:

different mean values

Apart from modifying the mean values in preprocess stage, are there other approaches to take the zero-point into account in ArmNN settings?

Rahn80643 avatar May 18 '22 02:05 Rahn80643

I'm closing this due to inactivity, if you require support please reopen.

morgolock avatar Feb 09 '24 10:02 morgolock