英文:
Error: ImportError: cannot import name 'model_urls' from 'torchvision.models.vgg'
问题
我想使用CRAFT文本检测器模块。我安装了所有必需的包,但当我尝试运行示例代码时,我遇到了一个错误:
ImportError: 无法从'torchvision.models.vgg'中导入名称'model_urls'
我查找了解决方案,但没有一个有效。
有任何建议吗?
英文:
I want to use the CRAFT text detector module. I installed all the required packages, but when I try to run the example code, I get
ImportError: cannot import name 'model_urls' from 'torchvision.models.vgg'
I looked for solutions, but none of them worked.
Any suggestions ?
答案1
得分: 1
model_urls
显然被移除了,因为它在整个代码库中不一致(参见GitHub 上的此评论)。
作者建议通过删除对不存在模块的导入并获取模型 URL 信息的方式来更新您的代码,例如这样:
import pkgutil
import torchvision
from importlib import import_module
def get_torchvision_models():
model_urls = dict()
for _, name, ispkg in pkgutil.walk_packages(torchvision.models.__path__):
if ispkg:
continue
_zoo = import_module(f'torchvision.models.{name}')
if hasattr(_zoo, 'model_urls'):
_urls = getattr(_zoo, 'model_urls')
model_urls.update(_urls)
return model_urls
英文:
Apparently model_urls
was removed because it was inconsistent across the code base
(see this comment on Github).
The authors recommend to update your code by removing the import for a non-existing module and getting model URL information for instance like this:
import pkgutil
import torchvision
from importlib import import_module
def get_torchvision_models():
model_urls = dict()
for _, name, ispkg in pkgutil.walk_packages(torchvision.models.__path__):
if ispkg:
continue
_zoo = import_module(f'torchvision.models.{name}')
if hasattr(_zoo, 'model_urls'):
_urls = getattr(_zoo, 'model_urls')
model_urls.update(_urls)
return model_urls
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论