forked from AChepurnoi/cnn-interpretability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.py
38 lines (28 loc) · 1.3 KB
/
pipeline.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
import argparse
from src.data import CelebaData
from src.train import Trainer, Evaluation
from src.utils import load_checkpoint
from src.config import config
from src.net import VggNetwork
import torch
parser = argparse.ArgumentParser()
parser.add_argument("--epochs", help="Number of epochs to train", type=int, default=1)
parser.add_argument("--batch", help="Number of epochs to train", type=int, default=1)
parser.add_argument("--workers", help="Checkpoint name", type=int, default=6)
parser.add_argument("--checkpoint", help="Checkpoint name", type=str, default=None)
args = parser.parse_args()
print("Arguments: {}".format(args))
print("Config: {}".format(config))
net = VggNetwork(out=2)
if args.checkpoint is not None:
extra = load_checkpoint(net, args.checkpoint)
train_data = CelebaData("data/train.csv")
val_data = CelebaData("data/val.csv")
train_loader = torch.utils.data.DataLoader(train_data, batch_size=args.batch, num_workers=args.workers, shuffle=True)
val_loader = torch.utils.data.DataLoader(val_data, batch_size=args.batch, num_workers=args.workers, shuffle=True)
trainer = Trainer(net, config)
eval = Evaluation(net, config)
for i in range(args.epochs):
trainer.run(train_loader, epochs=1)
result = eval.run(val_loader)
print(f"Validation result: {result['loss']} / {result['accuracy']}")