I learned to use fastai in the kaggle race and had problems making predictions at the end.
Here’s a link to the contest and a screenshot of the data format:
Here is my code:
tfms=get_transforms()
test_images=ImageList.from_folder(data_dir/‘test’)
data=(ImageList.from_folder(data_dir/‘train’)
.split_by_rand_pct()
.label_from_func(get_label)
.add_test(test_images)
.transform(tfms,size=299)
.databunch(bs=8)
.normalize(imagenet_stats))model=models.resnet50(pretrained=True)
learn=Learner(data,model,metrics=[error_rate,accuracy])learn.fit_one_cycle(10)
learn.export()predict_learn=load_learner(data_dir/‘train’)
preds,_=predict_learn.get_preds()
print(preds.shape)
or
pred,_=predict_learn.predict(test_images)
All of them make mistakes like this:
in addition, this error occurs when using predict(test_images):
how should i solve that two error?