mrdbourke / pytorch-deep-learning

Materials for the Learn PyTorch for Deep Learning: Zero to Mastery course.
https://learnpytorch.io
MIT License
9.68k stars 2.88k forks source link

ModuleNotFoundError: No module named 'going_modular' #687

Open NaiyerRafique opened 9 months ago

NaiyerRafique commented 9 months ago

In the paper replicating code when I write the following:

# For this notebook to run with updated APIs, we need torch 1.12+ and torchvision 0.13+
try:
    import torch
    import torchvision
    assert int(torch.__version__.split(".")[1]) >= 12, "torch version should be 1.12+"
    assert int(torchvision.__version__.split(".")[1]) >= 13, "torchvision version should be 0.13+"
    print(f"torch version: {torch.__version__}")
    print(f"torchvision version: {torchvision.__version__}")
except:
    print(f"[INFO] torch/torchvision versions not as required, installing nightly versions.")
    !pip3 install -U torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
    import torch
    import torchvision
    print(f"torch version: {torch.__version__}")
    print(f"torchvision version: {torchvision.__version__}")

I get the following error:

[INFO] Couldn't find going_modular or helper_functions scripts... downloading them from GitHub.
Cloning into 'pytorch-deep-learning'...
remote: Enumerating objects: 4028, done.
remote: Counting objects: 100% (1216/1216), done.
remote: Compressing objects: 100% (213/213), done.
remote: Total 4028 (delta 1065), reused 1098 (delta 1000), pack-reused 2812
Receiving objects: 100% (4028/4028), 651.38 MiB | 9.16 MiB/s, done.
Resolving deltas: 100% (2358/2358), done.
Updating files: 100% (248/248), done.
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-66-d2111b068830>](https://localhost:8080/#) in <cell line: 18>()
     18 try:
---> 19     from going_modular.going_modular import data_setup, engine
     20     from helper_functions import download_data, set_seeds, plot_loss_curves

ModuleNotFoundError: No module named 'going_modular'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-66-d2111b068830>](https://localhost:8080/#) in <cell line: 18>()
     26     get_ipython().system('mv pytorch-deep-learning/helper_functions.py . # get the helper_functions.py script')
     27     get_ipython().system('rm -rf pytorch-deep-learning')
---> 28     from going_modular.going_modular import data_setup, engine
     29     from helper_functions import download_data, set_seeds, plot_loss_curves

ModuleNotFoundError: No module named 'going_modular'

Importing the helper_functions works but somehow the going_modular is constantly giving an error. Can you tell me what is wrong?

mrdbourke commented 9 months ago

Hi @NaiyerRafique ,

This is strange.

I just re-ran Notebook 08 - PyTorch Paper Replicating in Google Colab and found it worked.

I was able to download the going_modular scripts as well as import various helper functions.

Where are you running the code?

Screenshot of running pytorch-deep-learning repo clone and code import
# Continue with regular imports
import matplotlib.pyplot as plt
import torch
import torchvision

from torch import nn
from torchvision import transforms

# Try to get torchinfo, install it if it doesn't work
try:
    from torchinfo import summary
except:
    print("[INFO] Couldn't find torchinfo... installing it.")
    !pip install -q torchinfo
    from torchinfo import summary

# Try to import the going_modular directory, download it from GitHub if it doesn't work
try:
    from going_modular.going_modular import data_setup, engine
    from helper_functions import download_data, set_seeds, plot_loss_curves
except:
    # Get the going_modular scripts
    print("[INFO] Couldn't find going_modular or helper_functions scripts... downloading them from GitHub.")
    !git clone https://github.com/mrdbourke/pytorch-deep-learning
    !mv pytorch-deep-learning/going_modular .
    !mv pytorch-deep-learning/helper_functions.py . # get the helper_functions.py script
    !rm -rf pytorch-deep-learning
    from going_modular.going_modular import data_setup, engine
    from helper_functions import download_data, set_seeds, plot_loss_curves