-
Notifications
You must be signed in to change notification settings - Fork 79
/
train.py
31 lines (24 loc) · 1.06 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
import yaml
from argparse import ArgumentParser
from pytorch_lightning import Trainer
from data.text_image_dm import TextImageDataModule
from models import CLIPWrapper
def main(hparams):
config_dir = 'models/configs/ViT.yaml' if 'ViT' in hparams.model_name else 'models/configs/RN.yaml'
with open(config_dir) as fin:
config = yaml.safe_load(fin)[hparams.model_name]
if hparams.minibatch_size < 1:
hparams.minibatch_size = hparams.batch_size
model = CLIPWrapper(hparams.model_name, config, hparams.minibatch_size)
del hparams.model_name
dm = TextImageDataModule.from_argparse_args(hparams)
trainer = Trainer.from_argparse_args(hparams, precision=16, max_epochs=32)
trainer.fit(model, dm)
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--model_name', type=str, required=True)
parser.add_argument('--minibatch_size', type=int, default=0)
parser = TextImageDataModule.add_argparse_args(parser)
parser = Trainer.add_argparse_args(parser)
args = parser.parse_args()
main(args)