Since we have learned more about what’s under the hood of fastai I was interested in building a model from scratch instead of using one of the preset like models.resnet34.
This has been harder then I expected.
I’m trying to recreate this model and then use it with the fastai cnn_learner - https://github.com/pytorch/examples/blob/master/mnist/main.py
class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 20, 5, 1) self.conv2 = nn.Conv2d(20, 50, 5, 1) self.fc1 = nn.Linear(4*4*50, 500) self.fc2 = nn.Linear(500, 10) def forward(self, x): x = F.relu(self.conv1(x)) x = F.max_pool2d(x, 2, 2) x = F.relu(self.conv2(x)) x = F.max_pool2d(x, 2, 2) x = x.view(-1, 4*4*50) x = F.relu(self.fc1(x)) x = self.fc2(x) return F.log_softmax(x, dim=1)
But I keep getting different errors depending on how I try and add it. Here is my Kaggle example. https://www.kaggle.com/pascalnoble/minst-fastai-3ab05b
learn = cnn_learner(data, Net,pretrained=False, metrics=error_rate)
Here is the error
TypeError: __init__() takes 1 positional argument but 2 were given
If added like this
learn = cnn_learner(data, Net(),pretrained=False, metrics=error_rate)
then the error is
TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not bool
If anyone has any ideas or solutions let me know.
It looks like someone else had a similar question that went unanswered -Customize Densenet model