torch.utils.model_zoo¶
移至 torch.hub。
-
torch.utils.model_zoo.
load_url
(url、model_dir=无、map_location=无、progress=True、check_hash=False、file_name=没有)¶ 在给定的 URL 处加载 Torch 序列化对象。
如果下载的文件是 zip 文件,它将自动 减压。
如果对象已经存在于 model_dir 中,则会对其进行反序列化,并且 返回。 的默认值 是 where,其中 是 返回的
目录。
model_dir
<hub_dir>/checkpoints
hub_dir
- 参数
url (string) – 要下载的对象的 URL
model_dir (string, optional) – 保存对象的目录
map_location (可选) – 指定如何重新映射存储位置的函数或字典(参见 torch.load)
progress (bool, optional) – 是否向 stderr 显示进度条。 默认值:True
check_hash (bool, optional) – 如果为 True,则 URL 的文件名部分应遵循命名约定,其中前 8 个或更多 文件内容的 SHA256 哈希值的数字。哈希值用于 确保名称唯一并验证文件的内容。 默认值:False
filename-<sha256>.ext
<sha256>
file_name (string, optional) – 下载文件的名称。如果未设置,则将使用 Filename from。
url
例
>>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')