onnx2tf: [FastestDet] The absolute error of `AveragePool`, `GlobalAveragePool` is quite large

Issue Type

Others

onnx2tf version number

1.5.12

onnx version number

1.13.0

tensorflow version number

2.10.0

Download URL for ONNX

https://github.com/PINTO0309/onnx2tf/releases/download/1.1.28/fastestdet.onnx https://github.com/PINTO0309/onnx2tf/releases/download/1.1.28/ppmattingv2_stdc1_human_480x640.onnx

Parameter Replacement JSON

N/A

Description

  1. Personal
  2. The absolute error of AveragePool is quite large. In addition, there is almost no error in other OPs.
    onnx2tf -i fastestdet.onnx -cotof -cotoa 1e-4
    
    image image
  3. At this time I do not know the cause of the larger error.
  4. I want to generate a tfite model with small accuracy degradation.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Screenshot from 2023-01-17 13-23-21

The images above are outputs of average pooling 2d from tflite, onnx, and tflite output divided by onnx output. As shown in image, output is same except the padded edges. I think we can get same output by padding slightly more and slice useless part. By the way, what was the bug you mentioned in #121?

https://github.com/PINTO0309/onnx2tf/blob/27d635f5a962b14f9655aa48e5c5660083217cc2/onnx2tf/ops/AveragePool.py#L129-L134 It looks line 133 is not appropriate for pooling operation. When stride is larger than 1, this line is always True. After that line, padding mode is always ‘valid’.

Also, according to https://stackoverflow.com/questions/50543862/tensorflow-tf-nn-avg-pool-with-same-padding-does-not-average-over-padded-pi, tensorflow default action looks like count_include_pad=False, same like onnx. But there is no option for user to change it. I guess, In this case, explicit padding and pad mode ‘valid’ caused output difference between onnx and tflite.

Keep trying to fix, but this problem is quite complicated than I thought.