作者|facebookresearch
編譯|Flin
來源|Github
detectron2.checkpoint軟體包
class detectron2.checkpoint.Checkpointer(model: torch.nn.modules.module.Module, save_dir: str = '', *, save_to_disk: bool = True, **checkpointables)
-
源代碼:https://detectron2.readthedocs.io/_modules/fvcore/common/checkpoint.html#Checkpointer
-
基類: object
-
可以保存/加載模型以及其他可檢查點物件的檢查點,
__init__(model:torch.nn.modules.module.Module,save_dir:str ='',*,save_to_disk:bool = True,** checkpointables )
- 引數:
- model(nn.Module):模型,
- save_dir(str):保存和查找檢查點的目錄,
- save_to_disk(bool):如果為True,則將檢查點保存到磁盤,否則禁用此檢查點的保存,
- checkpointables(object):任何可檢查點的物件,即具有state_dict()和load_state_dict()方法的物件,例如,它可以像 Checkpointer(model,"dir",optimizer = optimizer)一樣使用,
save(name:str,** kwargs )
- 將模型和檢查點轉儲到檔案中,
- 引數:
- name(str):檔案名,
- kwargs(dict):要保存的額外任意資料,
load(path:str )
-
從給定的檢查點加載,當路徑指向網路檔案時,必須在所有級別上呼叫此函式,
-
引數:
- path(str):檢查點的路徑或url,如果為空,將不會加載任何內容,
- 回傳值: dict ,從檢查點加載的尚未處理的額外資料,例如,用
save(**extra_data)()保存的內容 ,
has_checkpoint()
- 回傳值: bool ,目標目錄中是否存在檢查點,
get_checkpoint_file()
- 回傳值: str, 目標目錄中的最新檢查點檔案,
get_all_checkpoint_files()
- 回傳值: list,目標中所有可用的檢查點檔案(.pth檔案)目錄,
resume_or_load(path:str,*,resume:bool = True )
-
如果resume為True,則此方法嘗試從最后一個檢查點(如果存在)恢復,否則,從給定路徑加載檢查點,重新開始中斷的訓練作業時,這很有用,
-
引數:
- path(str)–檢查點的路徑,
- resume(bool)–如果為True,則從最后一個檢查點恢復(如果存在),
- 回傳值:和load()一樣,
tag_last_checkpoint(last_filename_basename: str)
- 標記最后一個檢查點,
- 引數: last_filename_basename(str),最后一個檔案名的基本名稱,
class detectron2.checkpoint.PeriodicCheckpointer(checkpointer: Any, period: int, max_iter: int = None, max_to_keep: int = None)
-
源代碼:https://detectron2.readthedocs.io/_modules/fvcore/common/checkpoint.html#PeriodicCheckpointer
-
基類: object
-
定期保存檢查點,當
.step(iteration)被呼叫時,如果迭代是周期的倍數或達到最大值,,它將在給定的checkpointer上執行checkpointer.save,
__init__(checkpointer: Any, period: int, max_iter: int = None, max_to_keep: int = None)
- 引數:
- checkpointer(Any):用于保存的checkpointer物件
- checkpoints
- period(int):保存檢查點的時間段,
- max_iter(int):最大迭代次數,到達后,將保存一個名為"model_final"的檢查點,
- max_to_keep(int):保留的最新當前檢查點的最大數量,以前的檢查點將被洗掉
step(iteration: int, **kwargs)
-
在給定的迭代中執行適當的操作,
-
引數:
- iteration (int)–當前迭代,范圍為[0,max_iter-1],
- kwargs(Any)–要保存的額外資料,與
Checkpointer.save()中的相同 ,
save(name: str, **kwargs)
-
與相同的論點Checkpointer.save(),使用此方法可以在計劃之外手動保存檢查點,
-
引數:
- name(str):檔案名,
- kwargs(Any):要保存的額外資料,與
Checkpointer.save()中的相同.
classdetectron2.checkpoint.DetectionCheckpointer(model, save_dir='', *, save_to_disk=None, **checkpointables)
- 源代碼:https://detectron2.readthedocs.io/_modules/detectron2/checkpoint/detection_checkpoint.html#DetectionCheckpointer
- 基類: fvcore.common.checkpoint.Checkpointer
與Checkpointer相同,但能夠處理Detectron和Detectron2模型庫中的模型,并將轉換應用于舊模型,
原文鏈接:https://detectron2.readthedocs.io/modules/checkpoint.html
歡迎關注磐創AI博客站:
http://panchuang.net/
sklearn機器學習中文官方檔案:
http://sklearn123.com/
歡迎關注磐創博客資源匯總站:
http://docs.panchuang.net/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/18090.html
標籤:其他
