PyTorch 预训练权重保存位置

  • 使用Pytorch pretrained=True时,IDE下很慢,有时候还会报错。于是点击链接用浏览器下载。
  • 这时候才能看到我真实的带宽。下载完后放在哪里呢?
  • 顺藤摸瓜:
    if pretrained:
        state_dict = load_state_dict_from_url(model_urls[arch],
                                              progress=progress)

通过load_state_dict_from_url,继续定位

def load_state_dict_from_url(url, model_dir=None, map_location=None, progress=True, check_hash=False):
    r"""Loads the Torch serialized object at the given URL.

    If downloaded file is a zip file, it will be automatically
    decompressed.

    If the object is already present in `model_dir`, it's deserialized and
    returned.
    The default value of `model_dir` is ``$TORCH_HOME/checkpoints`` where
    environment variable ``$TORCH_HOME`` defaults to ``$XDG_CACHE_HOME/torch``.
    ``$XDG_CACHE_HOME`` follows the X Design Group specification of the Linux
    filesytem layout, with a default value ``~/.cache`` if not set.


    Example:
        >>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')

后面还有一大堆。。。

于是可以看到 default value of model_dir is $TORCH_HOME/checkpoints

我使用的Ubuntu,$TORCH_HOME位于home/用户名/ 下,找到 .cache。这是一个隐藏文件,如果没有看到,按下Ctrl+H就可以了。在这里面找到torch文件夹,就可以看到checkpoints了。

总结,位于 /home/你的用户名/.cache/torch/checkpoints

把下载的训练权重.pth文件放到这里面,就可以识别到了!

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值