Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Fixed flops estimation for pooling #19

Merged
merged 2 commits into from
Jul 21, 2020
Merged

fix: Fixed flops estimation for pooling #19

merged 2 commits into from
Jul 21, 2020

Conversation

frgfm
Copy link
Owner

@frgfm frgfm commented Jul 21, 2020

Previously, integer output size for adaptive pooling was not supported:

from torchscan import summary
import torch.nn as nn
summary(nn.Sequential(nn.Conv2d(3, 32, 3), nn.AdaptiveAvgPool2d(1)).cuda(), (3, 256, 256))

would produce

~/Documents/torch-scan/torchscan/modules/flops.py in flops_adaptive_avgpool(module, input, output)
    220     # Approximate kernel_size using ratio of spatial shapes between input and output
    221     kernel_size = tuple(i_size // o_size if (i_size % o_size) == 0 else i_size - o_size * (i_size // o_size) + 1
--> 222                         for i_size, o_size in zip(input.shape[2:], module.output_size))
    223 
    224     # for each spatial output element, sum elements in kernel scope and div by kernel size

TypeError: zip argument #2 must support iteration

This PR fixes the issue by casting the output size to a tuple of integer of the correct size.

Since the pooling size can be passed as integer or tuple and is not cast into a single type, the evaluation was failing for an integer size.
@frgfm frgfm added bug Something isn't working module: modules Related to modules labels Jul 21, 2020
@frgfm frgfm added this to the 0.1.1 milestone Jul 21, 2020
@frgfm frgfm self-assigned this Jul 21, 2020
@codecov
Copy link

codecov bot commented Jul 21, 2020

Codecov Report

Merging #19 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
+ Coverage   89.10%   89.14%   +0.04%     
==========================================
  Files           8        8              
  Lines         468      470       +2     
==========================================
+ Hits          417      419       +2     
  Misses         51       51              
Impacted Files Coverage Δ
torchscan/modules/flops.py 99.01% <100.00%> (+0.01%) ⬆️

@frgfm frgfm merged commit 22b7868 into master Jul 21, 2020
@frgfm frgfm deleted the pool-flops-fix branch July 21, 2020 17:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working module: modules Related to modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant