作者|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/