init model checkpoint
(exe, init_checkpoint_path, main_program)
| 45 | |
| 46 | |
| 47 | def init_checkpoint(exe, init_checkpoint_path, main_program): |
| 48 | """init model checkpoint""" |
| 49 | assert os.path.exists( |
| 50 | init_checkpoint_path), "[%s] cann't be found." % init_checkpoint_path |
| 51 | |
| 52 | def existed_persitables(var): |
| 53 | if not fluid.io.is_persistable(var): |
| 54 | return False |
| 55 | return os.path.exists(os.path.join(init_checkpoint_path, var.name)) |
| 56 | |
| 57 | fluid.io.load_vars( |
| 58 | exe, |
| 59 | init_checkpoint_path, |
| 60 | main_program=main_program, |
| 61 | predicate=existed_persitables) |
| 62 | print("Load model from {}".format(init_checkpoint_path)) |
| 63 | |
| 64 | |
| 65 | def init_pretraining_params(exe, |