[SOLVED]"Can't get Attribute ImageItemList" Error in Production App

I have tried many different scenarios to get my learning model for Lesson 2 into a production environment. I keep getting stalled with the following error:

Step 7/9 : RUN python app/server.py —>
Running in f573ecea5f5d /usr/local/lib/python3.6/site-packages/torch/serialization.py:435: SourceChangeWarning: source code of class ‘torchvision.models.resnet.BasicBlock’ has changed. you can retrieve the original source code by accessing the object’s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning)

Traceback (most recent call last):
File “app/server.py”, line 61, in <module> learn = loop.run_until_complete(asyncio.gather(*tasks))[0]
File “/usr/local/lib/python3.6/asyncio/base_events.py”, line 484, in run_until_complete return future.result()
File “app/server.py”, line 56, in setup_learner learn.load(model_file_name)
File “/usr/local/lib/python3.6/site-packages/fastai/basic_train.py”, line 245, in load state = torch.load(self.path/self.model_dir/f’{name}.pth’, map_location=device)
File “/usr/local/lib/python3.6/site-packages/torch/serialization.py”, line 368, in load return _load(f, map_location, pickle_module)
File “/usr/local/lib/python3.6/site-packages/torch/serialization.py”, line 542, in _load result = unpickler.load()
AttributeError: Can’t get attribute ‘ImageItemList’ on <module ‘fastai.vision.data’ from ‘/usr/local/lib/python3.6/site-packages/fastai/vision/data.py’>
The command ‘/bin/sh -c python app/server.py’ returned a non-zero code: 1
ERROR: build step 0 “gcr.io/cloud-builders/docker” failed: exit status 1

I’m thinking somehow when I have exported my learning model it doesn’t have the correct settings to then be used in my App but I’m unsure what that would be.

Any help would be much appreciated.

I think it’s called ImageList now. Meaning, you might be on different fastai version between where you built the model and where you are trying to deploy it. Generally, in deployment, you probably want to pin any software you are using to a specific release.


A general rule of thumb is to use the same version of the library for training and production. Here as @radek has pointed out, a breaking API change was introduced in a library update. You could have avoided it if you used the same version of fastai library.

Thanks guys, as with the linked thread I installed an update of the fastai library:
sudo /opt/anaconda3/bin/conda install -c fastai fastai

Upgraded me to 1.0.46-1

Then I retrained my model. With the recent deprecations in my app I removed all of this:
data_bunch = ImageDataBunch.single_from_classes(path, classes, ds_tfms=get_transforms(), size=224).normalize(imagenet_stats)
learner = create_cnn(data_bunch, models.resnet34)

and replaced it with the new function call to pick up my export.pkl file in the models folder:
learner = load_learner(“models”)

Also, as Ji Xu mentioned, now to get the text from the pred_class variable from the learn.predict(img) function need to use pred_class.obj instead of just pred_class.

And then it worked. It’s not easy keeping up with the changes but things are definitely on the improve. Thanks to everyone who’s working on it and good luck to everyone learning.