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

Global average pooling #177

Open
cnuernber opened this issue Jun 1, 2017 · 1 comment
Open

Global average pooling #177

cnuernber opened this issue Jun 1, 2017 · 1 comment

Comments

@cnuernber
Copy link
Contributor

https://arxiv.org/pdf/1312.4400.pdf

@benkamphaus: Feel free to add any details we should consider when researching this feature.

@benkamphaus
Copy link
Contributor

Follow on paper has a video demo-ing use for saliency: http://cnnlocalization.csail.mit.edu/

The big takeaways are:

  • reduce huge expansion in parameters at final conv -> first fully connected layer
  • reduce the capacity of that layer to overfit
  • directly map from spatial features in a transparent way (saliency maps for free)

It's useful to compare how this works in keras here:

from keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D
from keras.layers import Dropout, Flatten, Dense
from keras.models import Sequential

model = Sequential([
    Conv2D(48, kernel_size=(3, 3), input_shape=(224, 224, 3), activation='relu', kernel_initializer='he_normal'),
    MaxPooling2D((2, 2)),
    Conv2D(96, kernel_size=(3, 3), activation='relu', kernel_initializer='he_normal'),
    MaxPooling2D((2, 2)),
    Conv2D(128, kernel_size=(3, 3), activation='relu', kernel_initializer='he_normal'),
    MaxPooling2D((2, 2)),
    GlobalAveragePooling2D(),
    Dense(133, activation='softmax'),
])


model.summary()

Leads to:

Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_39 (Conv2D)           (None, 222, 222, 48)      1344      
_________________________________________________________________
max_pooling2d_37 (MaxPooling (None, 111, 111, 48)      0         
_________________________________________________________________
conv2d_40 (Conv2D)           (None, 109, 109, 96)      41568     
_________________________________________________________________
max_pooling2d_38 (MaxPooling (None, 54, 54, 96)        0         
_________________________________________________________________
conv2d_41 (Conv2D)           (None, 52, 52, 128)       110720    
_________________________________________________________________
max_pooling2d_39 (MaxPooling (None, 26, 26, 128)       0         
_________________________________________________________________
global_average_pooling2d_9 ( (None, 128)               0         
_________________________________________________________________
dense_10 (Dense)             (None, 133)               17157     
=================================================================
Total params: 170,789
Trainable params: 170,789
Non-trainable params: 0

Versus:

model = Sequential([
    Conv2D(48, kernel_size=(3, 3), input_shape=(224, 224, 3), activation='relu', kernel_initializer='he_normal'),
    MaxPooling2D((2, 2)),
    Conv2D(96, kernel_size=(3, 3), activation='relu', kernel_initializer='he_normal'),
    MaxPooling2D((2, 2)),
    Conv2D(128, kernel_size=(3, 3), activation='relu', kernel_initializer='he_normal'),
    MaxPooling2D((2, 2)),
    Flatten(),
    Dense(133, activation='softmax'),
])


model.summary()

With:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_42 (Conv2D)           (None, 222, 222, 48)      1344      
_________________________________________________________________
max_pooling2d_40 (MaxPooling (None, 111, 111, 48)      0         
_________________________________________________________________
conv2d_43 (Conv2D)           (None, 109, 109, 96)      41568     
_________________________________________________________________
max_pooling2d_41 (MaxPooling (None, 54, 54, 96)        0         
_________________________________________________________________
conv2d_44 (Conv2D)           (None, 52, 52, 128)       110720    
_________________________________________________________________
max_pooling2d_42 (MaxPooling (None, 26, 26, 128)       0         
_________________________________________________________________
flatten_4 (Flatten)          (None, 86528)             0         
_________________________________________________________________
dense_11 (Dense)             (None, 133)               11508357  
=================================================================
Total params: 11,661,989
Trainable params: 11,661,989
Non-trainable params: 0

That's: 11,661,989 vs: 170,789 trainable params! Dropping those and getting better performance (as detailed in the paper).

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

No branches or pull requests

2 participants