3D convolution output shape

username: Naif40
cooked: <p>Hello,</p>
<p>I have the following 3D CNN that I use to predict the value (a property we want to predict) from the 3D images.</p>
<p>I want to compute the loss as Mean Absolute error (L1 loss) of each batch.</p>
<p>My current settings are:<br>
(batch size=1)<br>
image size = (64,64,64)<br>
the input tensor of images from train_loader to the network is shape of =[1,1,64,64,64]<br>
[1 for batch size of 1, 1 greyscale input (1 channel), 64 z dim, 64 x dim, 64 y dim]</p>
<p>class CNN3D(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(CNN3D,self).<strong>init</strong>()<br>
self.conv1=nn.Conv3d(1,32,kernel_size=5,stride=1,padding=0,dilation=1)<br>
self.bn1=nn.BatchNorm3d(32)<br>
self.pool1=nn.AvgPool3d(2,stride=2)<br>
self.conv2=nn.Conv3d(32,64,kernel_size=5,stride=1,padding=1,dilation=1)<br>
self.bn2=nn.BatchNorm3d(64)<br>
self.pool2=nn.AvgPool3d(kernel_size=2,stride=2,padding=0)<br>
self.fc1=nn.Linear(7<em>7</em>64,500)<br>
self.fc2=nn.Linear(500,50)<br>
self.fc3=nn.Linear(50,1)</p>
<pre><code>def forward(self,x):
    x=self.pool1(F.relu(self.bn1(self.conv1(x))))
    x=self.pool2(F.relu(self.bn2(self.conv2(x))))
    x=x.view(-1,7*7*64)
    x=F.relu(self.fc1(x))
    x=F.relu(self.fc2(x))
    x=self.fc3(x)
    
    return x
</code></pre>
<p>The output of the network (predictions) is shape: torch.Size([56, 1])<br>
The actual labels size are: torch.Size([1])</p>
<p>Shouldn’t be the size of the network output be a torch.Size([1)]? I don’t get why it outputs torch.Size([56, 1])?</p>
<p>My question is  how do i fix the output of the network to be a something like (N,1) where N is the batch size. Because the size of the network predictions and the actual labels should have the same size!</p>
<p>Can somone help?</p>

username: Balamurali_M
cooked: <p>Can you print the shape of x after each line in forward and show the results ?</p>

username: ahkarami
cooked: <p><a class="mention" href="/u/balamurali_m">@Balamurali_M</a> &amp; <a class="mention" href="/u/naif40">@Naif40</a><br>
There is a great reference for understanding different kinds of Convolution Operators (<strong>3D Convolution</strong>, <em>Spatially separable convolution</em>, <em>depthwise separable convolution</em>, etc.):<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://d3g6anj9jkury9.cloudfront.net/assets/favicons/favicon-16x16-c1207cd2f3a20fd50de0e585b4b307a3.png" class="site-icon" width="16" height="16">
      <a href="https://leanpub.com/convolutions-for-deep-learning" target="_blank" rel="nofollow noopener">Leanpub</a>
  </header>
  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:95/124;"><img src="https://d2sofvawe08yqg.cloudfront.net/convolutions-for-deep-learning/medium?1575064090" class="thumbnail"></div>

<h3><a href="https://leanpub.com/convolutions-for-deep-learning" target="_blank" rel="nofollow noopener">Deep Dive into Different Types of Convolutions for Deep Learning</a></h3>

<p>This book teaches the different types of convolution operators to design Deep Neural Networks with a variety of illustrative figures and examples. The basic concepts of the convolution operator to its advanced types are described with full details in...</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>