How do I load pretrained model using fastai implementation over PyTorch? Like in SkLearn I can use pickle to dump a model in file then load and use later. I've use .load() method after declaring learn instance like bellow to load previously saved weights:
arch=resnet34
data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=False)
learn.load('resnet34_test')
Then to predict the class of an image:
trn_tfms, val_tfms = tfms_from_model(arch,100)
img = open_image('circle/14.png')
im = val_tfms(img)
preds = learn.predict_array(im[None])
print(np.argmax(preds))
But It gets me the error:
ValueError: Expected more than 1 value per channel when training, got input size [1, 1024]
This code works if I use learn.fit(0.01, 3)
instead of learn.load()
. What I really want is to avoid the training step In my application.
This could be an edge case where batch size equals 1 for some batch. Make sure none of you batches = 1 (mostly the last batch)