class ConvNet(nn.Module):
def __init__(self, num_classes=2):
super(ConvNet, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(1, 16, kernel_size=5, stride=1, padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2))
self.layer2 = nn.Sequential(
nn.Conv2d(16, 32, kernel_size=5, stride=1, padding=2),
#nn.BatchNorm2d(64),
nn.ReLU(),
nn.MaxPool2d(kernel_size=5, stride=0))
self.drop_out = nn.Dropout()
self.fc1 = nn.Linear(15488, 152)
self.fc2 = nn.Linear(152,2)
def forward(self, x):
x.float()
out = self.layer1(x)
out = self.layer2(out)
out = out.reshape(out.size(0), -1)
out = self.drop_out(out)
out = self.fc1(out)
out = self.fc2(out)
return out
This architecture is so Computationally expensive and requires much memory , any recommendation to Minimize this computation and save the performance.
[ my model is take 224*224 picture and return 2 classes : P , N ]
thanks in advance
Yep, Basically you are making a pooling to get spatial size = 1. This way instead of having 15k parameters you will have just 1 parameter per channel. Then, fully connected is feasible. Besides you need a non-linearity between both FC. Otherwise it’s like having a single FC (as FC are linear layers)