cannot import name ‘mobilenet_v2’ from ‘torchvision.models’

This was the error I received when trying to import fastbook to study the excellent fast.ai course.

I had Python 3.9.1 installed and used pip to install the latest versions of torch, torchvision, and fastai

To spare the reader from boring war stories, here’s the bottom line:

  • Download the latest version of torchvision for your platform from https://download.pytorch.org/whl/torch_stable.html
    (for example cpu/torchvision-0.8.2%2Bcpu-cp39-cp39-win_amd64.whl is torchvision 0.8.2 for cpu on Windows for version 3.9 of C Python)
  • run pip install torchvision-0.8.2+cpu-cp39-cp39-win_amd64.whl (assuming this is the version you downloaded)
  • run pip install fastai --upgrade

You should now be able to import fastbook

Leave a Reply

Your email address will not be published. Required fields are marked *