Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'model_urls' from 'torchvision.models.vgg' #191

Open
AlejandroCampayo opened this issue Mar 24, 2023 · 10 comments

Comments

@AlejandroCampayo
Copy link

I get this error because apparently model_urls is no longer available for versions >0.13 in torchvision but I don't know how to fix it, downgrading the version does not seem to help...

@adamdoescode
Copy link

Downgrading to torchvision==0.13 worked for me

@tienipia
Copy link

tienipia commented Apr 3, 2023

Just remove broken codes.

basenet/vgg16_bn.py

from torchvision import models
[-] from torchvision.models.vgg import model_urls < Remove Ln. 7

...

class vgg16_bn(torch.nn.Module):
    def __init__(self, pretrained=True, freeze=True):
        super(vgg16_bn, self).__init__()
[-]        model_urls['vgg16_bn'] = model_urls['vgg16_bn'].replace('https://', 'http://') < Remove Ln. 25

@PooyanRezaeipour
Copy link

Downgrading to torchvision==0.13 worked for me

does not work bro

@rlrocha90
Copy link

comment the "from torchvision.models.vgg import model_urls"
It worked here!

Insert all this:

all = [
'VGG', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn',
'vgg19_bn', 'vgg19',
]

model_urls = {
'vgg11': 'https://download.pytorch.org/models/vgg11-bbd30ac9.pth',
'vgg13': 'https://download.pytorch.org/models/vgg13-c768596a.pth',
'vgg16': 'https://download.pytorch.org/models/vgg16-397923af.pth',
'vgg19': 'https://download.pytorch.org/models/vgg19-dcbb9e9d.pth',
'vgg11_bn': 'https://download.pytorch.org/models/vgg11_bn-6002323d.pth',
'vgg13_bn': 'https://download.pytorch.org/models/vgg13_bn-abd245e5.pth',
'vgg16_bn': 'https://download.pytorch.org/models/vgg16_bn-6c64b313.pth',
'vgg19_bn': 'https://download.pytorch.org/models/vgg19_bn-c79401a0.pth',
}

Or insert this for Resnet:

all = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101',
'resnet152']

model_urls = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth',
'resnet101': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth',
'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth',
}

Victorivus added a commit to Victorivus/CRAFT-pytorch that referenced this issue Dec 5, 2023
@ami-navon
Copy link

+1

@Devang-C
Copy link

comment the "from torchvision.models.vgg import model_urls" It worked here!

Insert all this:

all = [ 'VGG', 'vgg11', 'vgg11_bn', 'vgg13', 'vgg13_bn', 'vgg16', 'vgg16_bn', 'vgg19_bn', 'vgg19', ]

model_urls = { 'vgg11': 'https://download.pytorch.org/models/vgg11-bbd30ac9.pth', 'vgg13': 'https://download.pytorch.org/models/vgg13-c768596a.pth', 'vgg16': 'https://download.pytorch.org/models/vgg16-397923af.pth', 'vgg19': 'https://download.pytorch.org/models/vgg19-dcbb9e9d.pth', 'vgg11_bn': 'https://download.pytorch.org/models/vgg11_bn-6002323d.pth', 'vgg13_bn': 'https://download.pytorch.org/models/vgg13_bn-abd245e5.pth', 'vgg16_bn': 'https://download.pytorch.org/models/vgg16_bn-6c64b313.pth', 'vgg19_bn': 'https://download.pytorch.org/models/vgg19_bn-c79401a0.pth', }

Or insert this for Resnet:

all = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152']

model_urls = { 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', 'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth', 'resnet50': 'https://download.pytorch.org/models/resnet50-19c8e357.pth', 'resnet101': 'https://download.pytorch.org/models/resnet101-5d3b4d8f.pth', 'resnet152': 'https://download.pytorch.org/models/resnet152-b121ed2d.pth', }

This worked for me. I had problem in the easyocr library that was using the vgg models. Made the changes that you mentioned in their modules.py and it worked. Thank you very much.

@MKaczkow
Copy link

MKaczkow commented Feb 21, 2024

For current version of torchvision (0.16.2) the import should be:

from torchvision.models.vgg import VGG16_BN_Weights

but the code is not used anyway, so best to just remove it like mentioned:

Just remove broken codes.

basenet/vgg16_bn.py

from torchvision import models
[-] from torchvision.models.vgg import model_urls < Remove Ln. 7

...

class vgg16_bn(torch.nn.Module):
    def __init__(self, pretrained=True, freeze=True):
        super(vgg16_bn, self).__init__()
[-]        model_urls['vgg16_bn'] = model_urls['vgg16_bn'].replace('https://', 'http://') < Remove Ln. 25

Also, check this SO post.

@vikasr111
Copy link

I am facing the same issue. Is there a chance we can commit the fix in this repo?
It'd make the life easier.

@MKaczkow
Copy link

I think there is a PR currently open:
#202
But tbh, I don't understand why bbox.py is also modified

@CrasCris
Copy link

rlrocha90

If you have proxy config didn't work :c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants