AttributeError: Caught AttributeError in DataLoader worker process 0

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:

kaggle

%E6%8D%95%E8%8E%B7

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?

I find that if I use the trained learn directly to get_preds, there is no error, but if I use the learn obtained by load_learner for prediction, an error will be reported

Could be to different fastai versions (even minor version) in both environments. Check fastai.version in the exporting and also in the loading environment.