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, 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 雜湊的前八位或更多位數。雜湊用於確保名稱唯一並驗證檔案的內容。預設值:False
- file_name (str, 可選) – 下載檔案的名稱。如果未設定,將使用 - url中的檔名。
- weights_only (bool, 可選) – 如果為 True,則只會載入權重,而不會載入複雜的醃製物件。建議用於不受信任的來源。請參閱 - load()以取得更多詳細資訊。
 
- 返回類型
 - 範例 - >>> state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')