Issue when importing fastai.vision.all

Hello All,
I’ve been trying to get fastai setup in an AWS sagemaker notebook but I keep running into the following traceback error whenever I try to do the following:

from fastai.vision.all import *
from fastai.data.all import *

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/tmp/ipykernel_22462/3895247406.py in <module>
      1 #fastai imports
----> 2 from fastai.vision.all import *
      3 from fastai.data.all   import *

~/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages/fastai/vision/all.py in <module>
----> 1 from . import models
      2 from ..basics import *
      3 from ..callback.all import *
      4 from .augment import *
      5 from .core import *

~/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages/fastai/vision/models/__init__.py in <module>
----> 1 from . import xresnet
      2 from . import unet
      3 from .tvm import *

~/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages/fastai/vision/models/xresnet.py in <module>
     10 
     11 # Cell
---> 12 from ...torch_basics import *
     13 try: from torchvision.models.utils import load_state_dict_from_url
     14 except ModuleNotFoundError: from torch.hub import load_state_dict_from_url

~/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages/fastai/torch_basics.py in <module>
      9 from .imports import *
     10 from .torch_imports import *
---> 11 from .torch_core import *
     12 from .layers import *
     13 from .losses import *

~/anaconda3/envs/amazonei_pytorch_latest_p37/lib/python3.7/site-packages/fastai/torch_core.py in <module>
     29 
     30 # Cell
---> 31 @delegates(plt.subplots, keep=True)
     32 def subplots(nrows=1, ncols=1, figsize=None, imsize=3,suptitle=None, **kwargs):
     33     if figsize is None:

NameError: name 'delegates' is not defined

I’ve tried reinstalling fastai with conda, pip, and even using the fastai docker images, but I keep getting this error that seems to traceback to a delegates call in the fastai torch_core.py file in the fastai repo.

Does anyone have any ideas for what could be causing this or how to fix it?

Hey, delegates is a fastcore function, is fastcore installed correctly? I would have thought that conda would install that alongside fastai, what command did you use to install fastai?
If you do have the time, you can check out the Live Coding sessions where Jeremy goes through the installation and setup process in detail.

Hey, thanks for pointing that out. I ended up creating a new environment for fastai and reinstalling everything via conda there. That seems to have solved this issue. Now if I could find an updated object detection walkthrough that goes through using learner.get_preds() that would solve a lot more of my issues…

1 Like