Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculation of AvgPooling #55

Closed
MarkusAmann opened this issue Oct 31, 2019 · 5 comments
Closed

calculation of AvgPooling #55

MarkusAmann opened this issue Oct 31, 2019 · 5 comments

Comments

@MarkusAmann
Copy link

Could you please give a closer explanation for the calculation of the AvgPool FLOPs? Despite I know that the impact of pooling layers is minimal, I'd like to understand the calculation. As I get from the code the formular for 2dAvgPooling you use is: (kernel_size + 1) * H_out * W_out * in_channels * out_channels
But if I consider the formular on the pytorch website I'd calculate them as follows:
For each kernel beeing applied on your input you have kernel_size * kernel_size - 1 additions plus one division plus one multiplication of your kernel_size inside the denominator. You apply out_channels kernels on in_channels input channels which result in a H_out * W_out output. This is the computation for all multiplications and additions. To be compliant with the regular understanding of MACs and FLOPs you devide by 2 as two MACs result in one FLOP. So finally I get the formular: FLOPs = (kernel_size * kernel_size - 1) * H_out * W_out * in_channels * out_channels / 2

@Lyken17
Copy link
Owner

Lyken17 commented Oct 31, 2019

I think you suggestion is correct. In total there are H_out * W_out * out_channels pixels and each pixel takes ** in_channels * (kernel_size * kernel_size - 1) ** operations.

For MACs and FLOPs, it is not simple 2 times calculation. In short, it depends how you count the multiplication for floating numbers. I will refactor the codebase to fix the issue.

@MarkusAmann
Copy link
Author

Thank you! Will you please let me know as soon as you fixed the code, so that I can update the python package?

@Lyken17
Copy link
Owner

Lyken17 commented Jan 12, 2020

After talking to an expert in hardware, I made a clarification of MACs and FLOPs. For AVGPooling, the updated MAC should be H_out * W_out * out_channels. If you agree with it, I will update the corresponding code recently.

@Lyken17
Copy link
Owner

Lyken17 commented Jan 21, 2020

@fortunex3000 any comments?

@Lyken17 Lyken17 closed this as completed May 14, 2020
@llbin-oppo
Copy link

After talking to an expert in hardware, I made a clarification of MACs and FLOPs. For AVGPooling, the updated MAC should be H_out * W_out * out_channels. If you agree with it, I will update the corresponding code recently.

But if you do this, it is different from the statistical method of TensorFlow and the user’s conventional perception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants