-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patheval.py
More file actions
59 lines (48 loc) · 1.63 KB
/
Copy patheval.py
File metadata and controls
59 lines (48 loc) · 1.63 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (C) 2023 Mitsubishi Electric Research Laboratories (MERL)
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from argparse import ArgumentParser
from pathlib import Path
from pytorch_lightning import Trainer
from torch.utils.data import DataLoader
from lsx_dataset import LSXDataset
from separate import DEFAULT_PRE_TRAINED_MODEL_PATH, read_checkpoint
def _lightning_eval():
parser = ArgumentParser()
parser.add_argument(
"--root-dir",
type=Path,
required=True,
help="The path to the LSX directory containing ``tr``, ``cv``, and ``tt`` directories.",
)
parser.add_argument(
"--checkpoint",
type=Path,
default=DEFAULT_PRE_TRAINED_MODEL_PATH,
help="Path to trained model weights. Can be a pytorch_lightning checkpoint or pytorch state_dict",
)
parser.add_argument("--gpu-device", default=-1, type=int, help="The gpu device for model inference. (default: -1)")
args = parser.parse_args()
test_dataset = LSXDataset(args.root_dir, "tt")
test_loader = DataLoader(
test_dataset,
batch_size=1,
num_workers=0,
drop_last=False,
)
if args.gpu_device >= 0:
devices = [args.gpu_device]
accelerator = "gpu"
else:
devices = "auto"
accelerator = "cpu"
trainer = Trainer(
devices=devices,
accelerator=accelerator,
enable_progress_bar=True, # this will print the results to the command line
limit_test_batches=1.0,
)
model = read_checkpoint(args.checkpoint)
trainer.test(model, test_loader)
if __name__ == "__main__":
_lightning_eval()