【Debug】访问Huggingface和timm报错:ReadTimeoutError(“HTTPSConnectionPool(host=‘huggingface.co‘, port=443)

1. Error information

UserWarning: Mapping deprecated model name vit_base_resnet50_384 to current vit_base_r50_s16_384.orig_in21k_ft_in1k.
  **kwargs,
'(ReadTimeoutError("HTTPSConnectionPool(host='huggingface.co', port=443): Read timed out. (read timeout=10)"), '(Request ID: a2623e19-f380-47a6-9e64-5ed169b5b593)')' thrown while requesting HEAD https://huggingface.co/timm/vit_base_r50_s16_384.orig_in21k_ft_in1k/resolve/main/model.safetensors

2. Source code


    model = DPTDepthModel(backbone='vitb_rn50_384', num_channels=3) # DPT Hybrid
    
    checkpoint = torch.load(pretrained_weights_path, map_location=map_location)
    if 'state_dict' in checkpoint:
        state_dict = {}
        for k, v in checkpoint['state_dict'].items():
            state_dict[k[6:]] = v
    else:
        state_dict = checkpoint

    model.load_state_dict(state_dict)
    model.to(device)

3. 问题分析

访问huggingface出了问题,但是服务器已经挂了梯子,网络连接正常。

之后查看要访问的网址:https://huggingface.co/timm/vit_base_r50_s16_384.orig_in21k_ft_in1k/resolve/main/model.safetensors

主要到其中的timm 是之前我们pip 下来的一个包,它提供了预训练模型和各种网络组件,所以可能是我们单独pip install的过程中出了问题。

4. 解决方法

timm降版本,目前为0.9.12 ,降到0.4.5

pip install timm==0.4.5

问题解决后的正常终端输出:

Downloading: "https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-vitjx/jx_vit_base_resnet50_384-9fd3c705.pth" to /root/.cache/torch/hub/checkpoints/jx_vit_base_resnet50_384-9fd3c705.pth

5. 另外一种更为通用的方法

切换镜像到huggingface的国内版本:

在代码中加入

import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

注意这一步一定要放在import diffusers之前,可以放在主python文件的第一句话,比如下面这么放,也可以多放几处试试

在这里插入图片描述

完结撒花✿✿ヽ(°▽°)ノ✿

Reference:
[1]. Unknown model (vit_base_resnet50_384) · Issue #14 · isl-org/DPT (github.com)
[2]. 使用Huggingface镜像站hf-mirror.com下载资源_hf.mirror-CSDN博客

  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值