-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtrain.py
69 lines (53 loc) · 1.78 KB
/
train.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import argparse
import sys
import logging
from torch.utils.data import DataLoader
import pytorch_lightning as pl
from data.argoverse.argo_csv_dataset import ArgoCSVDataset
from data.argoverse.utils.torch_utils import collate_fn_dict
from model.crat_pred import CratPred
# Make newly created directories readable, writable and descendible for everyone (chmod 777)
os.umask(0)
root_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, root_path)
log_dir = os.path.dirname(os.path.abspath(__file__))
logging.getLogger("pytorch_lightning").setLevel(logging.INFO)
parser = argparse.ArgumentParser()
parser = CratPred.init_args(parser)
def main():
args = parser.parse_args()
dataset = ArgoCSVDataset(args.val_split, args.val_split_pre, args)
val_loader = DataLoader(
dataset,
batch_size=args.val_batch_size,
num_workers=args.val_workers,
collate_fn=collate_fn_dict,
pin_memory=True
)
dataset = ArgoCSVDataset(args.train_split, args.train_split_pre, args)
train_loader = DataLoader(
dataset,
batch_size=args.batch_size,
num_workers=args.workers,
collate_fn=collate_fn_dict,
pin_memory=True,
drop_last=False,
shuffle=True
)
checkpoint_callback = pl.callbacks.ModelCheckpoint(
filename="{epoch}-{loss_train:.2f}-{loss_val:.2f}-{ade1_val:.2f}-{fde1_val:.2f}-{ade_val:.2f}-{fde_val:.2f}",
monitor="loss_val",
save_top_k=-1,
)
model = CratPred(args)
trainer = pl.Trainer(
default_root_dir=log_dir,
callbacks=[checkpoint_callback],
gpus=args.gpus,
weights_save_path=None,
max_epochs=args.num_epochs
)
trainer.fit(model, train_loader, val_loader)
if __name__ == "__main__":
main()