I wanted to implement xception network in pytorch, So i tried to implement the blue part in this architecture given below
.And this is my program which I’ve written to do so,
class classifier(nn.Module):
def init(self):
super().init()
self.conv1 = nn.Conv2d(3, 32, 3, stride=2)
self.batchnorm1 = nn.BatchNorm2d(32)
self.conv2 = nn.Conv2d(32, 64, 3)
self.batchnorm2 = nn.BatchNorm2d(64)
self.conv3 = nn.Conv2d(64, 128, 1, stride=2)
self.depthwise1 = nn.Conv2d(64, 64, 3, padding=1, groups=64)
self.pointwise1 = nn.Conv2d(64, 128, 1)
self.batchnorm3 = nn.BatchNorm2d(128)
self.depthwise2 = nn.Conv2d(128, 128, 3, padding=1, groups=128)
self.pointwise2 = nn.Conv2d(128, 128, 1)
self.depthwise3 = nn.Conv2d(128, 128, 3, padding=1, groups=128)
self.pointwise3 = nn.Conv2d(128,256,1)
self.batchnorm4 = nn.BatchNorm2d(256)
self.depthwise4 = nn.Conv2d(256, 256, 3, padding=1, groups=256)
self.pointwise4 = nn.Conv2d(256, 256, 1)
self.conv4 = nn.Conv2d(128, 256, 1, stride=2)
self.conv5 = nn.Conv2d(256, 728, 1, stride=2)
self.depthwise5 = nn.Conv2d(256, 256, 3, padding=1, groups=256)
self.pointwise5 = nn.Conv2d(256, 728, 1)
self.batchnorm5 = nn.BatchNorm2d(728)
self.depthwise6 = nn.Conv2d(728, 728, 3, padding=1, groups=728)
self.pointwise6 = nn.Conv2d(728, 728, 1)
self.pool = nn.MaxPool2d(3,stride=2)
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
model=classifier()
And I’m getting this error
—> 40 x1 = torch.add(y,x)
41 x2 = F.relu(x1)
42 y1 = F.relu(self.batchnorm4(self.pointwise3(self.depthwise3(x2))))
RuntimeError: The size of tensor a (73) must match the size of tensor b (74) at non-singleton dimension 3
Can anyone help me through this!!