urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

When training the model, load some pre training models, such as VGg. The code is as follows

model = torchvision.models.vgg19(pretrained=True)

Train will display

Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to /root/.cache/torch/checkpoints/vgg19-dcbb9e9d.pth

Then an error occurred:

socket.gaierror: [Errno -3] Temporary failure in name resolution
and
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

This is because the pre training model cannot be downloaded, so it needs to be downloaded from the Internet
therefore, it is more convenient to download the model first, find a way to connect to the Internet, and then input the link automatically https://download.pytorch.org/models/vgg19-dcbb9e9d.pth
Then put the downloaded. PTH model file under a fixed path, such as

/home/team/torch/models/pre_ model/vgg19-dcbb9e9d.pth

Finally, change the code to

model = torchvision.models.vgg19(pretrained=False)
pthfile = r'/home/team/torch/models/pre_model/vgg19-dcbb9e9d.pth'
model.load_state_dict(torch.load(pthfile))```

Read More: