timm.create_model() connect error

文章讲述了如何在Windows系统中使用timm库下载并加载预训练的tf_efficientnet_b3_ns模型权重,涉及科学上网和权重路径配置。

timm.create_model()下载预训练的权重会网络报错
先打印网络权重的地址

pretrained_cfg = timm.models.create_model(cfg.backbone).default_cfg
print(pretrained_cfg)


#再用windows电脑科学上网,下载这个权重

https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_b3_ns-9d44bf68.pth

#再写一个路径指向这个权重

pretrained_cfg_overlay=dict(file='./xxx/tf_efficientnet_b3_ns-9d44bf68.pth')
import timm
in_chans = cfg.n_channels
encoder = timm.create_model(
            cfg.backbone,
            pretrained=cfg.pretrained,
            features_only=True,
            in_chans=in_chans,
            pretrained_cfg_overlay=dict(file=
            '/xxx/tf_efficientnet_b3_ns-9d44bf68.pth')
        )

Traceback (most recent call last): File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_transports\default.py", line 101, in map_httpcore_exceptions yield File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_transports\default.py", line 250, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_sync\connection_pool.py", line 256, in handle_request raise exc from None File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_sync\connection_pool.py", line 236, in handle_request response = connection.handle_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_sync\connection.py", line 101, in handle_request raise exc File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_sync\connection.py", line 78, in handle_request stream = self._connect(request) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_sync\connection.py", line 124, in _connect stream = self._network_backend.connect_tcp(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_backends\sync.py", line 207, in connect_tcp with map_exceptions(exc_map): File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\contextlib.py", line 158, in __exit__ self.gen.throw(value) File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectTimeout: timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\file_download.py", line 1602, in _get_metadata_or_catch_error metadata = get_hf_file_metadata( ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\utils\_validators.py", line 89, in _inner_fn return fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\file_download.py", line 1528, in get_hf_file_metadata response = _httpx_follow_relative_redirects(method="HEAD", url=url, headers=hf_headers, timeout=timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\file_download.py", line 283, in _httpx_follow_relative_redirects response = http_backoff( ^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\utils\_http.py", line 402, in http_backoff return next( ^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\utils\_http.py", line 312, in _http_backoff_base response = client.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_client.py", line 825, in request return self.send(request, auth=auth, follow_redirects=follow_redirects) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_client.py", line 914, in send response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_client.py", line 942, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_client.py", line 979, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_client.py", line 1014, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_transports\default.py", line 249, in handle_request with map_httpcore_exceptions(): File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\contextlib.py", line 158, in __exit__ self.gen.throw(value) File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\httpx\_transports\default.py", line 118, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectTimeout: timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\medical image\t1\pytorch-classification-master\pytorch-classification-master\main.py", line 145, in <module> main() File "D:\medical image\t1\pytorch-classification-master\pytorch-classification-master\main.py", line 67, in main worker(0, 1, cfg) File "D:\medical image\t1\pytorch-classification-master\pytorch-classification-master\main.py", line 101, in worker model = generate_model(cfg) ^^^^^^^^^^^^^^^^^^^ File "D:\medical image\t1\pytorch-classification-master\pytorch-classification-master\modules\builder.py", line 10, in generate_model model = build_model(cfg) ^^^^^^^^^^^^^^^^ File "D:\medical image\t1\pytorch-classification-master\pytorch-classification-master\modules\builder.py", line 56, in build_model model = timm.create_model( ^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\timm\models\_factory.py", line 138, in create_model model = create_fn( ^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\timm\models\resnet.py", line 1552, in resnet50 return _create_resnet('resnet50', pretrained, **dict(model_args, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\timm\models\resnet.py", line 791, in _create_resnet return build_model_with_cfg(ResNet, variant, pretrained, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\timm\models\_builder.py", line 457, in build_model_with_cfg load_pretrained( File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\timm\models\_builder.py", line 226, in load_pretrained state_dict = load_state_dict_from_hf(pretrained_loc, weights_only=True, cache_dir=cache_dir) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\timm\models\_hub.py", line 240, in load_state_dict_from_hf cached_file = hf_hub_download( ^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\utils\_validators.py", line 89, in _inner_fn return fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\file_download.py", line 991, in hf_hub_download return _hf_hub_download_to_cache_dir( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\file_download.py", line 1117, in _hf_hub_download_to_cache_dir _raise_on_head_call_error(head_call_error, force_download, local_files_only) File "C:\Users\Lenovo\.conda\envs\mypytorch\Lib\site-packages\huggingface_hub\file_download.py", line 1713, in _raise_on_head_call_error raise LocalEntryNotFoundError( huggingface_hub.errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.
最新发布
11-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值