torch.utils.model_zoo¶
已移动到 torch.hub。
- torch.utils.model_zoo.load_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None)¶
加载给定网址上的 Torch 序列化对象。
如果下载的文件是 zip 文件,它将被自动解压缩。
如果对象已经在model_dir中,它会被反序列化并返回。 默认值为
model_dir,即<hub_dir>/checkpoints,其中hub_dir是由get_dir()返回的目录。- Parameters:
url (str) – 要下载对象的URL
模型目录 (str, 可选) – 保存对象的目录
map_location (可选) – 指定如何重映射存储位置的函数或字典(参见 torch.load)
进度 (bool, 可选) – 是否在stderr中显示进度条。 默认值:True
check_hash (bool, 可选) – 如果为 True,URL 的文件名部分应遵循命名约定
filename-<sha256>.ext其中<sha256>是文件内容的 SHA256 哈希值的前八个或更多位数字。该哈希用于确保名称唯一并验证文件内容。 默认值:Falsefile_name (字符串, 可选) – 下载文件的名称。如果没有设置,将使用
url中的文件名。
- Return type:
示例
>>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')