使用pth文件创建model

预训练好的pth文件获取途径:

①Git开源项目里会有下载链接;

②翻墙去huggingface里搜索。Hugging Face – The AI community building the future.

情况一:如果该模型在timm中存在,则可以将下载好的pth文件放到XX/user/.cache/torch/hub/checkpoints目录下。以fasternet_s.pth文件为例,然后在代码中写:

import timm
model=timm.models.create_model('fasternet_s')

情况二:如果该模型不在timm中,则假设将internimage_s.pth文件放到本地的A目录下,则代码应写:

checkpoint = torch.hub.load_state_dict_from_url(url='A目录', map_location="cpu",check_hash=True,file_name="internimage_s.pth")
model.load_state_dict(checkpoint["model"])

tips:如何查看该模型是否在timm中,可以使用通用匹配符的方式,案例如下:

import timm
from pprint import pprint
model_names = timm.list_models('*resne*t*')
pprint(model_names)

>>> ['cspresnet50',
 'cspresnet50d',
 'cspresnet50w',
 'cspresnext50',
...
]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值