Answers.Body: <p>This one is a bit crazy:</p>
  <pre><code>pool1 = nn.AvgPool3d(kernel_size = (361, 1, 1), stride= 1)
  </code></pre>
  <p>because it averages large numbers of the features at once. Very little information about individual features will remain after doing that.</p>
  <p>The most obvious one you have not tried is this:</p>
  <pre><code>pool3 = nn.AvgPool3d(kernel_size = (3, 1, 1), stride= (3, 1, 1))
  </code></pre>
  <p>which includes all the feature data, and does not try to average over large amounts of it at a time. I expect <code>pool3</code> to perform better than <code>pool1</code> in terms of speed, and better than <code>pool2</code> in terms of metrics for the trained CNN.</p>
  <p>If your goal is to reduce number of feature maps from 540 to 180, then pooling is not usually a good choice of operation. The motivation behind pooling assumes that there is some consistent metric space that it is pooling over - and this is used to decide values of size and stride. The sequence of channels will not usually have such a metric, it is usually arbitrary result of learning.</p>
  <p>Instead, the usual way to reduce number of channels between layers is to add a new convolution layer, with the desired number of output channels. In this scenario it is also common to use a kernel size of 1. This adds learnable parameters to the CNN, and those will learn an optimal compression of the channels for your problem.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-12T07:59:51.500Z
Answers.LastActivityDate: 2021-10-12T12:31:56.633Z
Answers.LastEditDate: 2021-10-12T12:31:56.633Z
Answers.UserDisplayName: Neil Slater
Body: <p>Suppose I have three batches of feature maps, each of size <span class="math-container">$180 \times 100 \times 100$</span>. I want to concatenate all these feature maps channel-wise, and then resize them into a single feature map. The batch size is equal to 10.</p>
  <p>Consider the following code in PyTorch</p>
  <pre><code>import torch
  from torch import nn
  
  x1 = torch.randn(10, 180, 100, 100)
  x2 = torch.randn(10, 180, 100, 100)
  x3 = torch.randn(10, 180, 100, 100)
  
  
  pool1 = nn.AvgPool3d(kernel_size = (361, 1, 1), stride= 1)
  pool2 = nn.AvgPool3d(kernel_size = 1, stride= (3, 1, 1))
  
  final_1_x = pool1(torch.cat((x1, x2, x3), 1))
  final_2_x = pool2(torch.cat((x1, x2, x3), 1))
  
  print(final_1_x.shape)
  print(final_2_x.shape)
  </code></pre>
  <p>and its output is</p>
  <pre><code>torch.Size([10, 180, 100, 100])
  torch.Size([10, 180, 100, 100])
  </code></pre>
  <p>You can observe that both types of polling I did are able to give a feature map of the desired size. But the first one takes a large amount of time with unsatisfactory results and the second one ignores many values in the input feature maps. I don't know whether it is okay to ignore or not.</p>
  <p>I want to know the recommended way to perform polling in order to get the desired size of feature maps. Is there any such recommended way to perform pooling?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-12T07:46:25.610Z
Comments.Text: Why do you want to pool over channels? That's an unusual choice, because channels do not usually have any sequence or metric that would make the operation correspond to something useful
Comments.UserDisplayName: Neil Slater
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-12T07:53:40.873Z
Comments.Text: @NeilSlater That is the reason for asking [this](https://ai.stackexchange.com/questions/32013/what-are-the-recommended-ways-to-change-shape-of-feature-maps-channel-wise-other) question. I want to achieve that without some parametric model, but need to capture information.
Comments.UserDisplayName: hanugm
Tags: <convolutional-neural-networks><pytorch><pooling>
Title: Is there any recommended way to perform pooling in this context?
UserDisplayName: hanugm
ThreadText: # Is there any recommended way to perform pooling in this context?
  
  (Asked by: username_0 on 2021-10-11)
  
  Suppose I have three batches of feature maps, each of size $180 \times 100 \times 100$. I want to concatenate all these feature maps channel-wise, and then resize them into a single feature map. The batch size is equal to 10.
  Consider the following code in PyTorch
  import torch
  from torch import nn
  
  x1 = torch.randn(10, 180, 100, 100)
  x2 = torch.randn(10, 180, 100, 100)
  x3 = torch.randn(10, 180, 100, 100)
  
  
  pool1 = nn.AvgPool3d(kernel_size = (361, 1, 1), stride= 1)
  pool2 = nn.AvgPool3d(kernel_size = 1, stride= (3, 1, 1))
  
  final_1_x = pool1(torch.cat((x1, x2, x3), 1))
  final_2_x = pool2(torch.cat((x1, x2, x3), 1))
  
  print(final_1_x.shape)
  print(final_2_x.shape)
  
  and its output is
  torch.Size([10, 180, 100, 100])
  torch.Size([10, 180, 100, 100])
  
  You can observe that both types of polling I did are able to give a feature map of the desired size. But the first one takes a large amount of time with unsatisfactory results and the second one ignores many values in the input feature maps. I don't know whether it is okay to ignore or not.
  I want to know the recommended way to perform polling in order to get the desired size of feature maps. Is there any such recommended way to perform pooling?
  
  **Tags:** convolutional-neural-networks, pytorch, pooling
  > **Comments:**
  > **username_1**: Why do you want to pool over channels? That's an unusual choice, because channels do not usually have any sequence or metric that would make the operation correspond to something useful  
  > **username_0**: @NeilSlater That is the reason for asking [this](https://ai.stackexchange.com/questions/32013/what-are-the-recommended-ways-to-change-shape-of-feature-maps-channel-wise-other) question. I want to achieve that without some parametric model, but need to capture information.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-10-12. Score: 2 | Accepted answer
  
  This one is a bit crazy:
  pool1 = nn.AvgPool3d(kernel_size = (361, 1, 1), stride= 1)
  
  because it averages large numbers of the features at once. Very little information about individual features will remain after doing that.
  The most obvious one you have not tried is this:
  pool3 = nn.AvgPool3d(kernel_size = (3, 1, 1), stride= (3, 1, 1))
  
  which includes all the feature data, and does not try to average over large amounts of it at a time. I expect pool3 to perform better than pool1 in terms of speed, and better than pool2 in terms of metrics for the trained CNN.
  If your goal is to reduce number of feature maps from 540 to 180, then pooling is not usually a good choice of operation. The motivation behind pooling assumes that there is some consistent metric space that it is pooling over - and this is used to decide values of size and stride. The sequence of channels will not usually have such a metric, it is usually arbitrary result of learning.
  Instead, the usual way to reduce number of channels between layers is to add a new convolution layer, with the desired number of output channels. In this scenario it is also common to use a kernel size of 1. This adds learnable parameters to the CNN, and those will learn an optimal compression of the channels for your problem.
  
  
  ---
  
  