I previously trained a resnet34 model using the fastai library, and have the weights.h5 file saved. With the latest version of fastai, do I still need to have non-empty train and valid folders in order to import my learner and predict on the test set?
Also, I’m currently looping through every test image and using learn.predict_array
, but is there a way to predict in batches on a test folder?
Example of what I’m currently doing just to load/predict:
PATH = '/path/to/model/'
sz = 224
arch=resnet34
tfms = tfms_from_model(resnet34, sz, aug_tfms=transforms_side_on, max_zoom=1.1)
data = ImageClassifierData.from_paths(PATH, tfms=tfms, bs=64)
learn = ConvLearner.pretrained(arch, data, precompute=False)
learn.unfreeze()
learn.load('224_all')
imgs = sorted(glob(os.path.join(test_path, '*.jpg')))
preds = []
_,val_tfms = tfms_from_model(resnet34, 224)
for n, i in enumerate(imgs):
im = val_tfms(open_image(i))[None]
preds.append(1-np.argmax(learn.predict_array(im)[0]))
There must be a cleaner way to do this by now, no?