-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_retrieval.py
45 lines (32 loc) · 1.28 KB
/
test_retrieval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# ------------------------------------------------------------------------------------
# Copyright (c) 2023 KakaoBrain. All Rights Reserved.
# Licensed under the MIT License [see LICENSE for details]
# ------------------------------------------------------------------------------------
import logging
import pprint
import pytorch_lightning as pl
from omegaconf import DictConfig
from noc.utils.main_utils import init_data_loader, init_hydra_config, init_model, init_trainer
logging.info("Inference with config:")
logging.getLogger().setLevel(logging.DEBUG)
def main():
# init cfg
cfg = init_hydra_config(mode="test")
# set random seed
if "seed" in cfg.experiment and cfg.experiment.seed >= 0:
pl.seed_everything(cfg.experiment.seed, workers=True)
# init dataloader
_, test_loader = init_data_loader(cfg, split="val")
# init model
cfg, model = init_model(cfg)
# init trainer
cfg, trainer = init_trainer(cfg)
if trainer.global_rank == 0:
# avoiding repeated print when using multiple gpus
logging.info(f"MODEL: {model}")
logging.info(cfg.pretty() if isinstance(cfg, DictConfig) else pprint.pformat(cfg))
# test
trainer.test(model, dataloaders=test_loader)
if __name__ == "__main__":
main()