torch.utils.model_zoo#
建立日期:2017年1月9日 | 最後更新日期:2025年6月11日
已遷移到 torch.hub。
- torch.utils.model_zoo.load_url(url, model_dir=None, map_location=None, progress=True, check_hash=False, file_name=None, weights_only=False)[來源]#
從給定 URL 載入 Torch 序列化物件。
如果下載的檔案是 zip 檔案,它將被自動解壓縮。
如果物件已存在於 model_dir 中,則將其反序列化並返回。
model_dir的預設值為<hub_dir>/checkpoints,其中hub_dir是get_dir()返回的目錄。- 引數
url (str) – 要下載物件的 URL
model_dir (str, 可選) – 儲存物件的目錄
map_location (可選) – 一個函式或字典,用於指定如何重新對映儲存位置(請參閱 torch.load)
progress (bool, 可選) – 是否向 stderr 顯示進度條。預設為 True
check_hash (bool, 可選) – 如果為 True,則 URL 的檔名部分應遵循命名約定
filename-<sha256>.ext,其中<sha256>是檔案內容的 SHA256 雜湊值的前八位或更多數字。該雜湊值用於確保名稱的唯一性並驗證檔案內容。預設為 Falsefile_name (str, 可選) – 下載檔案的名稱。如果未設定,將使用
url中的檔名。weights_only (bool, 可選) – 如果為 True,則僅載入權重,而不載入複雜的 pickled 物件。建議用於不可信的來源。有關更多詳細資訊,請參閱
load()。
- 返回型別
示例
>>> state_dict = torch.hub.load_state_dict_from_url( ... "https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth" ... )