Lesson 2 version 2: rexnext50 model unable to load, file not found error

I am trying to load the resnext50 model using the notebook provided by Jeremy, I am getting the following error.

FileNotFoundError: [Errno 2] No such file or directory: ‘/home/irshad/fastai/courses/dl1/fastai/weights/resnext_50_32x4d.pth’

1 Like

Sounds like you’re missing some of the weight files, you can find them here: http://files.fast.ai/models/weights.tgz


It worked, Thanks a lot :slight_smile:


Where did you place the weights folder? I’m using Google Colab and I’m getting the same error within a different directory. Due to user permission I cannot copy the weights folder into that directory

FileNotFoundError: [Errno 2] No such file or directory: ‘/usr/local/lib/python3.6/distpackages/fastai/weights/resnext_50_32x4d.pth’

Somehow I can’t get this to download on linux
If I click this link in this Chrome browser on my Mac I’m on it works. Not on Terminal in Linux.

wget http://files.fast.ai/models/weights.tgz166
–2018-04-02 06:05:03-- http://files.fast.ai/models/weights.tgz166
Resolving files.fast.ai (files.fast.ai)…
Connecting to files.fast.ai (files.fast.ai)||:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2018-04-02 06:05:03 ERROR 404: Not Found.

wget http://files.fast.ai/models/weights.tgz is the command, There is an additional 166 at the end.


Thank you.
If you’re still there,
In the lesson1-rxt50.ipynb notebook, do you know how I can get a list of the file locations generated for all the classifications it makes?

If I give it the command…

plot_val_with_title(rand_by_correct(True), “Correctly classified”)

It shows the value (between 0 and 1) and a thumbnail of the photo.
I haven’t been able to get it to tell me which file it classifies to what.
I put a ‘??’ in front of the commands that deal with these but I haven’t been able to trace back to the file paths.

I’d like to use the trained model with new photos, but I guess that’s another question. My eventual goal is to be able to do an os.rename to move the photos it classifies into the 1 folder and the 0 folder.
If you don’t want to get into all that just being able to find the file path name will do.

Hi, that’s explained that in Lesson 3, the code is at the top of the wiki page where he’s showing how to generate the submission file: Wiki: Lesson 3

Do you mean
‘00:39:30 Making an individual prediction on a single file’ ?
This will allow me to classify images if I add this to the bottom of the notebook after all the cells have run?
I could work that into a batch of new images.

I’m still kind of in the dark about how to get it to show the paths of the image files it classifies one way or the other.

btw, the code he uses to evaluate doesn’t work with the notebook I tried it on (lesson1-rxt50.ipynb).
The notebook Jeremy uses in that section is not in any of my directories. It seems to be gotten rid of.

Hi, are you saying that this code doesn’t work (I haven’t run it in a little while)?


… actually, you might need to wrap the np.exp(log_preds) in a mean function, he had to change the TTA code because you can’t mean the logs until after they’ve been exponentiated …

it should generate a file with the filenames and the predicted scores.

By “this code” you mean in your image?
I’m not sure what this code is. Is it something you made or is it from one of the notebooks in the course?

When I said the code didn’t work I meant because Jeremy at the time where he shows how to evaluate one image he is using a notebook that I do NOT have. They must have taken it out of the git when I got mine or something.

Yes, the image is from the notes right at the top of the lesson 3 wiki.

You’re right - the code doesn’t appear in the notebooks, but it only takes about a minute to transcribe it out of this image.

Ah, I see.
I never would have found that.
I didn’t know what I wanted to do was called a ‘submission file’.
Thank you.
I’ll pester you again if I can’t get it to work.

I find it hard to get an understanding of what’s supposed to be happening in order for what I want to happen. Like, what each command is. If it was just a glob.glob selection of all files (unrelated to any machine learning) and say, a for loop that classifies all files under x size I could get a handle on this. There’s no way in for me.

I tried the code in different places in the notebooks ‘lesson1.ipynb’ and ‘lesson1-rxt50.ipynb’
The first cell gives the error,

TypeError Traceback (most recent call last)
in ()
1 log_preds, y = learn.TTA(True)
2 probs = np.exp(log_preds)
----> 3 accuracy(log_preds, y), metrics.log_loss(y, probs)

~/fastai/courses/dl1/fastai/metrics.py in accuracy(preds, targs)
8 def accuracy(preds, targs):
----> 9 preds = torch.max(preds, dim=1)[1]
10 return (preds==targs).float().mean()

TypeError: torch.max received an invalid combination of arguments - got (numpy.ndarray, dim=int), but expected one of:

  • (torch.FloatTensor source)
  • (torch.FloatTensor source, torch.FloatTensor other)
    didn’t match because some of the keywords were incorrect: dim
  • (torch.FloatTensor source, int dim)
  • (torch.FloatTensor source, int dim, bool keepdim)

The accuracy call is just for show, do the other cells do what you need?

This code is running through batches of files in the test folder, classifying them using Test Time Augmentation, picking out the probabilities for each class, putting them into a pandas data frame, and then writing that to a file.

Looking at the code, there the probs = np.exp line might need to change … Jeremy used to take the mean of the TTA and then exponentiate it, but that doesn’t work (because you can’t mean logs). I think the correct answer for that is somewhere on these forums.

No. None of the cells do what I want them to do. All I want them to do is return the file location with every classification/probabilities. I’d like to do some pythonic things with the file locations and probabilities too but I think I could figure that out if I could get the notebook to return them.

I’m not sure the code in the image would return what I want. What’s writing to a file?
The code in that image is for which notebook? In what part of what notebook after the notebook has done what?

Jeremy made a post for what looks like was notebook 1 for how to classify on image at a time. I thought I might be able to get it to loop through batches or return classification file locations. It doesn’t work as is either.

1 Like

Is there any way to start small so I can get my foot in the door with this thing I want to do?
I know the model looks at the photo because it’s classifying it. Obviously.
So do all the photos have a position number? Can’t the path name be stored with this number?

Hi, have you solved this issue coz I am also using Google colab and I am getting the same error as well

Google colab try this
!wget http://files.fast.ai/models/weights.tgz
!mkdir /usr/local/lib/python3.6/dist-packages/fastai/weights
!tar -xvzf weights.tgz -C /usr/local/lib/python3.6/dist-packages/fastai/


downloading the weights via wget from http://files.fast.ai/models/weights.tgz to /usr/local/lib/python3.6/distpackages/fastai/ worked for me in google colab

1 Like