Downloading notebooks and environments

Hello everyone !

I’m using Anaconda and Jupyter on my computer and wanted to give a try with some notebooks I’ve been using during the GAN specialization. However, everytime I try to run it there is an import error from one thing or another.

The latest is this:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~\anaconda3\lib\site-packages\torchvision\models\utils.py in <module>
      1 try:
----> 2     from torch.hub import load_state_dict_from_url
      3 except ImportError:

ModuleNotFoundError: No module named 'torch.hub'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-d3d37a4a722e> in <module>
      2 from torch import nn
      3 from tqdm.auto import tqdm
----> 4 from torchvision import transforms
      5 from torchvision.datasets import MNIST
      6 from torchvision.utils import make_grid

~\anaconda3\lib\site-packages\torchvision\__init__.py in <module>
      1 import warnings
      2 
----> 3 from torchvision import models
      4 from torchvision import datasets
      5 from torchvision import ops

~\anaconda3\lib\site-packages\torchvision\models\__init__.py in <module>
----> 1 from .alexnet import *
      2 from .resnet import *
      3 from .vgg import *
      4 from .squeezenet import *
      5 from .inception import *

~\anaconda3\lib\site-packages\torchvision\models\alexnet.py in <module>
      1 import torch
      2 import torch.nn as nn
----> 3 from .utils import load_state_dict_from_url
      4 
      5 

~\anaconda3\lib\site-packages\torchvision\models\utils.py in <module>
      2     from torch.hub import load_state_dict_from_url
      3 except ImportError:
----> 4     from torch.utils.model_zoo import load_url as load_state_dict_from_url

ModuleNotFoundError: No module named 'torch.utils.model_zoo'

I’ve reinstalled pytorch, it’s at version 1.4.0 and torchvision is at 0.5.0

Is there a clean way to import notebooks and environments from coursera on a local machine ?

Hi, Barb.

There are several layers of issues here. There are no coherent instructions for doing this. Of course if you want to play this kind of game, it requires a certain amount of resourcefulness on your part. There are no end of problems that you can potentially encounter and (since this is not within the scope of any of these courses) it’s not reasonable to expect the mentors (who are unpaid fellow student volunteers) to be your personal IT support staff.

With that said, there are some pre-existing threads that should get you started.

The first issue is that you need more than just the notebooks. Most of them have ancillary local files as well. Here’s a thread that shows one approach for how to download everything.

The second big set of issues looks more relevant to the particular problem you show, which is that “versionitis” is a huge problem. All these spaces (python in general, support packages, TF, PyTorch, yadda, yadda) are highly dynamic over time. You need a way to duplicate the exact versions of all the installed packages that are expected by the particular notebook in question. Anaconda is a tool specifically engineered to support that. They have excellent documentation on their website (hint, hint :nerd_face:). Here is a thread which discusses for one of the DLS courses a bit about how to use “pip” and Anaconda to duplicate versions.

I wish you good luck on this adventure! It is highly likely that you will learn a lot in the process. :scream_cat:

1 Like

Hi paulinpaloalto,

Thanks for the comments. Yeah I’m not expecting full IT support ^^.
I’ll have a read at the threads you sent me.

To answer my own problem (that I finally solved):

Anaconda’s installer did no good for me, and I ended up removing everything.
Then I ran: conda install pytorch torchvision cudatoolkit=10.2 -c pytorch and it solved everything so far.

1 Like

Great! It looks like you are successfully launched on this path. If Anaconda initially didn’t work for you, I claim that just means you weren’t using it appropriately. This is literally what it is designed to accomplish: it lets you install and maintain a bunch of different customized environments each with a very specific set of versions of everything. Once you get them set up, then you can easily switch back and forth between them.

1 Like

Me not doing the appropriate usage of something specifically designed for it sounds likely. :stuck_out_tongue:

Anyway, so far so good

Dear Paul,

I am not sure if anyone has posted this solution so far but here is what I’ve just found.

  1. Open a notebook of an assignment.
  2. Click on Lab files button on the top right corner.

  1. Navigate to the assignment folder. It would be W4A2 in my case.

  1. Select and download it.

It downloads everything in the right way by zipping. Even h5 and .mat files are downloaded correctly that are complicated to get if the compression is done on a different view. This view.

For example, if you try to download .mat file by simply selecting, it won’t work. The download simply doesn’t start.

Hope this helps
Henrikh

Hi, Henrikh.

Thank you for pointing this out! It looks like a new “feature” from Coursera. I’d never noticed it before until you pointed it out just now. It does seem to work as you say: it creates a “zip” file called Files.zip containing the entire directory tree for the assignment. In the few experiments I’ve done so far, it seems to download the entire tree, regardless of your current working directory with the UI. I double checked that it correctly handles linux “symlinks”: there are several assignments with large pretrained models or large input files which are structured as symlinks pointing to a file in a different “read only” subtree and the zip file contains the target file, not the link.

But I did find at least one Course 4 assignment where the “Lab Files” button does not show up: the Face Recognition assignment in Week 4. In Week 1 of Course 5, only one out of the three assignments has that button. So it’s not universally available apparently. I’ll keep an eye on this.

Note that the reason you can’t directly download .mat or .h5 files is that browsers typically won’t let you download arbitrary binary files in formats that they don’t recognize. But they will accept standard “archive” formats like zip and tar.

Up to this point, we have recommended that people use “tar” to package up the files in a given assignment for download, because the Docker images for the assignments do not contain zip. Here’s a thread about how to use tar, but you’ve probably already seen that.

Dear Paul,

Thanks for the reply. I didn’t know that .h5 and .mat files were symlinks.
Downloading both by using 'tar czhvf *.tgz *.h5andtar czhvf *.tgz *.mat` worked as you explained in the shared above thread (Unable to download resnet50.h5 of Week 2's assignment Residual Networks - #2 by paulinpaloalto)!

In addition, I can assure you that direct downloading of the .h5 file worked, but I couldn’t download the .mat file of the assignment I mentioned above. I think the reason is the file size for .mat that is approximately 345MB, i.e., exceeds 100MB, whereas for .h5 file it is approximately 80MB.

Henrikh

thanks :stuck_out_tongue: