-
Notifications
You must be signed in to change notification settings - Fork 84
/
train_qcnet.py
57 lines (52 loc) · 2.76 KB
/
train_qcnet.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
# Copyright (c) 2023, Zikang Zhou. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from argparse import ArgumentParser
import pytorch_lightning as pl
from pytorch_lightning.callbacks import LearningRateMonitor
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.strategies import DDPStrategy
from datamodules import ArgoverseV2DataModule
from predictors import QCNet
if __name__ == '__main__':
pl.seed_everything(2023, workers=True)
parser = ArgumentParser()
parser.add_argument('--root', type=str, required=True)
parser.add_argument('--train_batch_size', type=int, required=True)
parser.add_argument('--val_batch_size', type=int, required=True)
parser.add_argument('--test_batch_size', type=int, required=True)
parser.add_argument('--shuffle', type=bool, default=True)
parser.add_argument('--num_workers', type=int, default=8)
parser.add_argument('--pin_memory', type=bool, default=True)
parser.add_argument('--persistent_workers', type=bool, default=True)
parser.add_argument('--train_raw_dir', type=str, default=None)
parser.add_argument('--val_raw_dir', type=str, default=None)
parser.add_argument('--test_raw_dir', type=str, default=None)
parser.add_argument('--train_processed_dir', type=str, default=None)
parser.add_argument('--val_processed_dir', type=str, default=None)
parser.add_argument('--test_processed_dir', type=str, default=None)
parser.add_argument('--accelerator', type=str, default='auto')
parser.add_argument('--devices', type=int, required=True)
parser.add_argument('--max_epochs', type=int, default=64)
QCNet.add_model_specific_args(parser)
args = parser.parse_args()
model = QCNet(**vars(args))
datamodule = {
'argoverse_v2': ArgoverseV2DataModule,
}[args.dataset](**vars(args))
model_checkpoint = ModelCheckpoint(monitor='val_minFDE', save_top_k=5, mode='min')
lr_monitor = LearningRateMonitor(logging_interval='epoch')
trainer = pl.Trainer(accelerator=args.accelerator, devices=args.devices,
strategy=DDPStrategy(find_unused_parameters=False, gradient_as_bucket_view=True),
callbacks=[model_checkpoint, lr_monitor], max_epochs=args.max_epochs)
trainer.fit(model, datamodule)