MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / load_test_checkpoint

Function load_test_checkpoint

slowfast/utils/checkpoint.py:475–522  ·  view source on GitHub ↗

Loading checkpoint logic for testing.

(cfg, model, backup=False)

Source from the content-addressed store, hash-verified

473
474
475def load_test_checkpoint(cfg, model, backup=False):
476 """
477 Loading checkpoint logic for testing.
478 """
479 # Load a checkpoint to test if applicable.
480 if cfg.TEST.CHECKPOINT_FILE_PATH != "":
481 # If no checkpoint found in MODEL_VIS.CHECKPOINT_FILE_PATH or in the current
482 # checkpoint folder, try to load checkpoint from
483 # TEST.CHECKPOINT_FILE_PATH and test it.
484 load_checkpoint(
485 cfg.TEST.CHECKPOINT_FILE_PATH,
486 model,
487 None,
488 cfg.NUM_GPUS > 1,
489 None,
490 inflation=False,
491 convert_from_caffe2=cfg.TEST.CHECKPOINT_TYPE == "caffe2",
492 )
493 elif backup:
494 backup_checkpoint = os.path.join(cfg.OUTPUT_DIR, "checkpoints", "checkpoint_backup.pyth")
495 load_checkpoint(backup_checkpoint, model, None, cfg.NUM_GPUS > 1)
496 elif cfg.TEST.TEST_BEST:
497 d = cfg.OUTPUT_DIR
498 names = g_pathmgr.ls(d)
499 names = [f for f in names if "best" in f]
500 name = sorted(names)[-1]
501 best_checkpoint = os.path.join(d, name)
502 load_checkpoint(best_checkpoint, model, None, cfg.NUM_GPUS > 1)
503 elif has_checkpoint(cfg.OUTPUT_DIR):
504 last_checkpoint = get_last_checkpoint(cfg.OUTPUT_DIR)
505 load_checkpoint(last_checkpoint, model, None, cfg.NUM_GPUS > 1)
506 elif cfg.TRAIN.CHECKPOINT_FILE_PATH != "":
507 # If no checkpoint found in TEST.CHECKPOINT_FILE_PATH or in the current
508 # checkpoint folder, try to load checkpoint from
509 # TRAIN.CHECKPOINT_FILE_PATH and test it.
510 load_checkpoint(
511 cfg.TRAIN.CHECKPOINT_FILE_PATH,
512 model,
513 None,
514 cfg.NUM_GPUS > 1,
515 None,
516 inflation=False,
517 convert_from_caffe2=cfg.TRAIN.CHECKPOINT_TYPE == "caffe2",
518 )
519 else:
520 logger.info(
521 "Unknown way of loading checkpoint. Using with random initialization, only for debugging."
522 )
523
524
525def load_train_checkpoint(cfg, model, optimizer, loss_scaler):

Callers

nothing calls this directly

Calls 4

load_checkpointFunction · 0.70
has_checkpointFunction · 0.70
get_last_checkpointFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected