Hi everyone,
I’m having trouble migrating code that worked on fastai v1 to fastai v2. Presume the following simple model:
class model2L(nn.Module):
def __init__(self, num_classes=2):
super(model2L, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=5, stride=1, padding=2),
nn.BatchNorm2d(32),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(32, 64, kernel_size=5, stride=1, padding=2),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.classifier = nn.Sequential(
nn.Dropout(0.5),
nn.Linear(56 * 56 * 64, num_classes),
)
def forward(self, x):
x = self.features(x)
x = torch.flatten(x, 1)
x = self.classifier(x)
return x
To apply it to some data, I do the following:
image_data = ImageDataLoaders.from_folder(ts_path, train='train', bs=batch_size, valid='valid', size=224)
eqs_model = model2L().cuda()
learn = Learner(image_data, eqs_model, loss_func=loss_func, metrics=accuracy)
The only difference between the procedure so far between the two versions is using ImageDataLoaders
, which seems to have replaced the v1 function ImageDataBunch
.
However, whenever I try to do anything with learn
, I get the following error which I never got in v1:
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x2880000 and 200704x2)
Does anyone have any idea of any changes between v1 and v2 that could be causing this? Maybe it has to do with the way that ImageDataLoaders
structures the data?
Thanks!