Swin-Transformer icon indicating copy to clipboard operation
Swin-Transformer copied to clipboard

Is the Flops calulated wrong?

Open choasup opened this issue 3 years ago • 2 comments

https://github.com/microsoft/Swin-Transformer/blob/2622619f70760b60a42b996f5fcbe7c9d2e7ca57/models/swin_transformer.py#L583

where
self.avgpool=self.norm: self.num_features * self.patches_resolution[0] * self.patches_resolution[1] // ((2 ** (self.num_layers  - 1)) ** 2)

so flops += self.num_features * self.patches_resolution[0] * self.patches_resolution[1] // (2 ** self.num_layers) // 2
eg. 768 * 7 * 7 * 2 = 768 * 56 * 56 // 16 // 2

choasup avatar Jul 21 '21 08:07 choasup

Hi @choasup, you are right, but the flops of avgpool is so negligible compared with the overall flops, so we just ignore it.

zeliu98 avatar Dec 20 '21 16:12 zeliu98

Hi @choasup, how did ((2 ** (self.num_layers - 1)) ** 2) simplified into (2 ** self.num_layers)? I'm so confused about the calculation of FLOPs for norm here, as in #165 Does anyone can answer my question? Thanks alot!

unclebuff avatar Apr 18 '22 10:04 unclebuff