Implementing xception network

username: vishnu_vardhan1
cooked: <p>I wanted to implement xception network in pytorch,  So i tried to implement the blue part in this architecture given below<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/e/2e1fccba31333f9b9c50444b1ceec3a30ae59bcd.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/2e1fccba31333f9b9c50444b1ceec3a30ae59bcd" title="Screenshot (9)_LI"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e1fccba31333f9b9c50444b1ceec3a30ae59bcd_2_690x387.jpeg" alt="Screenshot (9)_LI" data-base62-sha1="6A25QaOxh9dLMxTLdwTAPVd5SYB" width="690" height="387" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e1fccba31333f9b9c50444b1ceec3a30ae59bcd_2_690x387.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e1fccba31333f9b9c50444b1ceec3a30ae59bcd_2_1035x580.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/e/2e1fccba31333f9b9c50444b1ceec3a30ae59bcd.jpeg 2x" data-dominant-color="EAECED"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot (9)_LI</span><span class="informations">1044×586 132 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div> .<br>
And this is my program which I’ve written to do so,</p>
<p>class classifier(nn.Module):<br>
def <strong>init</strong>(self):<br>
super().<strong>init</strong>()<br>
self.conv1 = nn.Conv2d(3, 32, 3, stride=2)<br>
self.batchnorm1 = nn.BatchNorm2d(32)<br>
self.conv2 = nn.Conv2d(32, 64, 3)<br>
self.batchnorm2 = nn.BatchNorm2d(64)<br>
self.conv3 = nn.Conv2d(64, 128, 1, stride=2)<br>
self.depthwise1 = nn.Conv2d(64, 64, 3, padding=1, groups=64)<br>
self.pointwise1 = nn.Conv2d(64, 128, 1)<br>
self.batchnorm3 = nn.BatchNorm2d(128)<br>
self.depthwise2 = nn.Conv2d(128, 128, 3, padding=1, groups=128)<br>
self.pointwise2 = nn.Conv2d(128, 128, 1)<br>
self.depthwise3 = nn.Conv2d(128, 128, 3, padding=1, groups=128)<br>
self.pointwise3 = nn.Conv2d(128,256,1)<br>
self.batchnorm4 = nn.BatchNorm2d(256)<br>
self.depthwise4 = nn.Conv2d(256, 256, 3, padding=1, groups=256)<br>
self.pointwise4 = nn.Conv2d(256, 256, 1)<br>
self.conv4 = nn.Conv2d(128, 256, 1, stride=2)<br>
self.conv5 = nn.Conv2d(256, 728, 1, stride=2)<br>
self.depthwise5 = nn.Conv2d(256, 256, 3, padding=1, groups=256)<br>
self.pointwise5 = nn.Conv2d(256, 728, 1)<br>
self.batchnorm5 = nn.BatchNorm2d(728)<br>
self.depthwise6 = nn.Conv2d(728, 728, 3, padding=1, groups=728)<br>
self.pointwise6 = nn.Conv2d(728, 728, 1)<br>
self.pool = nn.MaxPool2d(3,stride=2)</p>
<pre><code>    self.fc1 = nn.Linear(262808, 4096)
    self.fc2 = nn.Linear(4096, 1024)
    self.fc3 = nn.Linear(1024, 102)
    self.dropout = nn.Dropout(p=0.5)


def forward(self,x):
    x = F.relu(self.batchnorm1(self.conv1(x)))
    x = F.relu(self.batchnorm2(self.conv2(x)))
    y = F.relu(self.batchnorm3(self.pointwise1(self.depthwise1(x))))
    y = self.pool(self.batchnorm3(self.pointwise2(self.depthwise2(y))))
    x = self.batchnorm3(self.conv3(x))
    x = torch.reshape(x,73)
    x1 = torch.add(y,x)
    x2 = F.relu(x1)
    y1 = F.relu(self.batchnorm4(self.pointwise3(self.depthwise3(x2))))
    y1 = self.pool(self.batchnorm4(self.pointwise4(self.depthwise4(y1))))
    x2 = self.batchnorm4(self.conv4(x2))
    x3 = torch.add(y1,x2)
    x3 = F.relu(x3)
    y2 = F.relu(self.batchnorm5(self.pointwise5(self.depthwise5(x3))))
    y2 = self.pool(self.batchnorm5(self.pointwise5(self.depthwise2(y2))))
    x3 = self.batchnorm5(self.conv5(x3))
    x4 = torch.add(y2,x3)
    x4 = F.relu(x4)

    x = x4.view(x4.shape[0],-1)
    x = self.dropout(F.relu(self.fc1(x)))
    x = self.dropout(F.relu(self.fc2(x)))
    x = F.log_softmax(self.fc3(x), dim=1)    
    return x
</code></pre>
<p>model=classifier()</p>
<p>And I’m getting this error<br>
—&gt; 40         x1 = torch.add(y,x)<br>
41         x2 = F.relu(x1)<br>
42         y1 = F.relu(self.batchnorm4(self.pointwise3(self.depthwise3(x2))))</p>
<p>RuntimeError: The size of tensor a (73) must match the size of tensor b (74) at non-singleton dimension 3<br>
Can anyone help me through this!!</p>

username: Johnny_Cash
cooked: <p>Could you figure out what the problem was <a class="mention" href="/u/vishnu_vardhan1">@vishnu_vardhan1</a> ? Running into the same.</p>