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

replaced mean on dimensions 2,3 by adaptive_avg_pooling2d #1838

Merged
merged 5 commits into from
Feb 13, 2020
Merged

replaced mean on dimensions 2,3 by adaptive_avg_pooling2d #1838

merged 5 commits into from
Feb 13, 2020

Conversation

talcs
Copy link
Contributor

@talcs talcs commented Jan 30, 2020

with destination of 1 (which is a Pytorch way to implement GlobalAvgPooling2D), to remove hardcoded dimension ordering

@talcs
Copy link
Contributor Author

talcs commented Jan 30, 2020

This pull request is following this issue: #1773

Since F.adaptive_avg_pool2d(x, 1) returns a tensor shaped as torch.Size([B, C, 1, 1]), I applied torch.squeeze on it, to get a torch.Size([B, C]) array

@codecov-io
Copy link

codecov-io commented Feb 2, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@5c49d99). Click here to learn what that means.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #1838   +/-   ##
========================================
  Coverage          ?   0.43%           
========================================
  Files             ?      92           
  Lines             ?    7389           
  Branches          ?    1113           
========================================
  Hits              ?      32           
  Misses            ?    7349           
  Partials          ?       8
Impacted Files Coverage Δ
torchvision/models/inception.py 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c49d99...d6b5279. Read the comment docs.

@talcs
Copy link
Contributor Author

talcs commented Feb 2, 2020

I first used squeeze to turn the [B,C,1,1] shaped avg pooling result to [B,C], but when B=1, the shape will become [C], which is incorrect. Hence, in order to keep the batch size dimension even when B=1, I had to use reshape(x.shape[0], -1).

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fmassa fmassa merged commit 1e27b53 into pytorch:master Feb 13, 2020
fmassa pushed a commit to fmassa/vision-1 that referenced this pull request Jul 8, 2020
* replaced mean on dimensions 2,3 by adaptive_avg_pooling2d with destination of 1, to remove hardcoded dimension ordering

* replaced reshape command by torch.squeeze after global_avg_pool2d, which is cleaner

* reshape rather than squeeze for BS=1

* remove import torch
facebook-github-bot pushed a commit that referenced this pull request Jul 8, 2020
)

Summary:
* replaced mean on dimensions 2,3 by adaptive_avg_pooling2d with destination of 1, to remove hardcoded dimension ordering

* replaced reshape command by torch.squeeze after global_avg_pool2d, which is cleaner

* reshape rather than squeeze for BS=1

* remove import torch

Pull Request resolved: #2416

Reviewed By: zhangguanheng66

Differential Revision: D22432590

Pulled By: fmassa

fbshipit-source-id: a335e8b9342833cfe02702ebea75041f09c4924e
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

Successfully merging this pull request may close these issues.

3 participants