These were my imports:
import fastai
from fastai.data.core import DataLoaders
from fastai.basics import *
from fastai.vision.core import *
from fastai.vision.data import *
from fastai.vision.augment import *
from fastai.vision import models
from fastai.vision.learner import Learner
from fastai.vision import models
Now, it’s this:
import fastai
from fastai.basics import *
from fastai.vision.core import *
from fastai.vision.data import *
from fastai.vision.augment import *
from fastai.vision import models
from fastai.vision import models
from fastai.callback.schedule import lr_find
I am also facing one more error. My custom dataloader is defined as follows:
class data_gen(torch.utils.data.Dataset):
def __init__(self, files):
self.files = files
def __getitem__(self, i):
file1 = self.files[i]
tmp = np.load(file1, allow_pickle=True)
img = tmp['x']
img = np.reshape(img,(1,img.shape[0], img.shape[1]))
img = torch.from_numpy(img).float()
return img
def __len__(self):
return len(self.files)
When I define a DataLoader
:
train_ds = data_gen(X_train)
test_ds = data_gen(X_test)
dls = DataLoaders.from_dsets(train_ds, test_ds, bs=batch_size, device='cuda:0')
learn = Learner(dls=dls,model=m,loss_func=F.mse_loss)
lr_find(learn)
I get the following error:
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [64, 1, 7, 7], but got 3-dimensional input of size [1, 512, 512] instead
So, in the data_gen
definition, I changed the shape of the image to (1, 1, 512, 512)
, which got rid of the error but I got another error:
TypeError: mse_loss() takes from 2 to 5 positional arguments but 16 were given
What do you suggest?