Using Cadene's pretrained model


Thank you always for your help.
I am testing pretrained models from

and am trying to run the example code

But an error occurred as follows:

runfile(‘C:/usr/local/Anaconda3/pretrained-models.pytorch/examples/’, wdir=‘C:/usr/local/Anaconda3/pretrained-models.pytorch/examples’)

File “C:\usr\local\Anaconda3\lib\site-packages\spyder\utils\site\”, line 705, in runfile
execfile(filename, namespace)

File “C:\usr\local\Anaconda3\lib\site-packages\spyder\utils\site\”, line 102, in execfile
exec(compile(, filename, ‘exec’), namespace)

File “C:/usr/local/Anaconda3/pretrained-models.pytorch/examples/”, line 305, in

File “C:/usr/local/Anaconda3/pretrained-models.pytorch/examples/”, line 125, in main
datasets.ImageFolder(valdir, val_tf),

File “C:\usr\local\Anaconda3\lib\site-packages\torchvision\datasets\”, line 178, in init

File “C:\usr\local\Anaconda3\lib\site-packages\torchvision\datasets\”, line 75, in init
classes, class_to_idx = find_classes(root)

File “C:\usr\local\Anaconda3\lib\site-packages\torchvision\datasets\”, line 23, in find_classes
classes = [d for d in os.listdir(dir) if os.path.isdir(os.path.join(dir, d))]

FileNotFoundError: [WinError 3] The system cannot find the path specified: ‘path_to_imagenet\val’

I am working on Anaconda3. Does this error come from my own system or Have I misunderstood the location for installation?

Thank you in advance:)

1 Like

Based on the error it seems you are not setting the --data argument (line of code).
The default value is set to path_to_imagenet.
Try to run the script again while passing the path to --data.

1 Like

Dear ptrblck,

Thank you for your reply.
I see that the --data argument is not set correctly on my environment.
But I am sorry that I cannot understand what the argparse does and even that I have not yet recognized what this code does.

At first I will try a little more to understand what you said.
Anyway, I appreciate your kind suggestion.

Thank you very much:)

argparse is used to call your script with arguments. Here is a small example:

python --data /home/petro_key/python/data -j 12 -b 64

As you can see some arguments are defined with a valid default value, e.g. the learning rate, while other arguments need to be set like data.

Basically argparse tries to parse all set arguments you pass to your script and sets the corresponding values.

It’s comparable with char *argv[] in C++, if you are familiar with it.

1 Like

Dear ptrblck,

Thank you very much again for your kind reply.
I now see what the argparse does thanks to your example.
The c++ similarity helped me as well!

I run the program at the Anaconda3\pretrained-models.pytorch\examples
directory as

python --data …/data -j 12 -b 64
but unfortunately it returned the same error as before.

Probably am I trying to evaluate an invalid folder?
Although the data folder has cat and croco images, they are not what this test program is assumed to use?

Thank you.

I’m not sure what’s expected in the --data directory, but you have three dots in your path. Probably you want to use two dots to get to the parent dir? Could you fix it and try it again?

1 Like

Dear ptrblck,

Thank you again and again for your reply.
It was certainly a typo of ‘…/data’; thank you for your correction.

As I tried it again as --data …/data, but the result was the same.
"The system cannot find the path specified:’…/data\val’ "

I probably have another problem in my system.

Thank you.

1 Like

Try it with --data ..\\data\\. I think Windows might address the paths with \\, but I’m not sure.

1 Like

Dear ptrblck,

Thank you for your reply.
I tried it and some other combinations like
–data …/data/
–data …\data
as well, but had the same error.

I installed this package below Anaconda3 directory,
but is it possible that I should have installed it in another directory?

Thank you.

Conda packages are usually installed inside the Anaconda directory.
You still have three dots in the path. Is it still a typo?

1 Like

Dear ptrblck,

I am sorry for my late reply.
And thank you for your reply.

It was a typo again. Really sorry for having confused you again.
The command is

python --data …\data\ -j 12 -b 64
and the error is
The system cannot find the path specified: ‘…\\data\\val’

I cannot figure out why it gives ‘…\\data\\val’ with two additional "\"s there.

I have also tried

python examples/ --data data -j 12 -b 64
in the pretrained-models.pytorch folder, but it was the same.

Thank you for your support.

Dear ptrblck,

I don"t know why this happens, but it seems that “…/” (just to be safe, I mean two dots plus a “/”) in the reply box is displayed as “…/” (three dots plus a “/”) here.

Sorry again for having confused you in my reply.

Thank you.

No worries. Could you check the content of your data directory, i.e. which subfolders etc. are present?
After a quick discussion with @tom, a wrong folder structure or something similar might be the issue here.

1 Like

Specifically, there is a tiny note in the docs that hints at the necessary preparation.
The stock imagenet validation set isn’t sorted into folders for the classes. For Linux, the docs link to a shell script that does it for you, it should not be too hard to make it into a .bat. This then needs to be put into a val folder that then mirrors the train folder.

Best regards


1 Like

Dear ptrblck,

Thank you for your reply and kind comment.
Here is the subfolders below the data folder:


2018/10/22 21:15 .
2018/10/22 21:15 …
2018/10/22 21:15 80,725 cat.jpg
2018/10/22 21:15 26,474 cat_224.jpg
2018/10/22 21:15 18,439 croco.jpg
2018/10/22 21:15 10,998 imagenet_classes.txt
2018/10/22 21:15 58,552 imagenet_synsets.txt

Thank you.

Dear tom,

Thank you for your reply.
According to your link, I imagine that I have not referred to the imagenet dataset and been doing around meaningless folder instead?

The following line in your link seems helpful.

This should simply be implemented with an ImageFolder dataset. The data is preprocessed as described here

Thank you.