Batch predicting with just test set

I previously trained a resnet34 model and have the weights.h5 file saved. With the current version of fastai, do I still need to have 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 batch predict on a test folder?

Example of what I’m currently doing to load/predict:

PATH = '/path/to/model/'
sz = 224
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)

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]

There must be a cleaner way to do this by now, no?

Also, I’d just like to confirm that the is just saving the weights and not the entire model? And if that’s the case, is there a way to save the model+weights together?

1 Like