forked from IRCVLab/AUE8088-PA1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
53 lines (42 loc) · 1.33 KB
/
test.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
46
47
48
49
50
51
52
53
"""
[AUE8088] PA1: Image Classification
- To run: (aue8088) $ python test.py --ckpt_file wandb/aue8088-pa1/ygeiua2t/checkpoints/epoch\=19-step\=62500.ckpt
"""
# Python packages
import argparse
# PyTorch & Pytorch Lightning
from lightning import Trainer
from torch.utils.flop_counter import FlopCounterMode
import torch
# Custom packages
from src.dataset import TinyImageNetDatasetModule
from src.network import SimpleClassifier
import src.config as cfg
torch.set_float32_matmul_precision('medium')
if __name__ == "__main__":
args = argparse.ArgumentParser()
args.add_argument('--ckpt_file',
type = str,
help = 'Model checkpoint file name')
args = args.parse_args()
model = SimpleClassifier(
model_name = cfg.MODEL_NAME,
num_classes = cfg.NUM_CLASSES,
)
datamodule = TinyImageNetDatasetModule(
batch_size = 1,
)
trainer = Trainer(
accelerator = cfg.ACCELERATOR,
devices = cfg.DEVICES,
precision = cfg.PRECISION_STR,
benchmark = True,
inference_mode = True,
logger = False,
)
trainer.validate(model, ckpt_path = args.ckpt_file, datamodule = datamodule)
# FLOP counter
x, y = next(iter(datamodule.test_dataloader()))
flop_counter = FlopCounterMode(model, depth=1)
with flop_counter:
model(x)