-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.py
48 lines (37 loc) · 1.22 KB
/
main.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
from model import MobileNetV2
from utils import parse_args, create_experiment_dirs
import torch.backends.cudnn as cudnn
from cifar10data import CIFAR10Data
from train import Train
def main():
# Parse the JSON arguments
try:
config_args = parse_args()
except:
print("Add a config file using \'--config file_name.json\'")
exit(1)
# Create the experiment directories
_, config_args.summary_dir, config_args.checkpoint_dir = create_experiment_dirs(config_args.experiment_dir)
model = MobileNetV2(config_args)
if config_args.cuda:
model.cuda()
cudnn.enabled = True
cudnn.benchmark = True
print("Loading Data...")
data = CIFAR10Data(config_args)
# data.plot_random_sample()
print("Data loaded successfully\n")
trainer = Train(model, data.trainloader, data.testloader, config_args)
if config_args.to_train:
try:
print("Training...")
trainer.train()
print("Training Finished\n")
except KeyboardInterrupt:
pass
if config_args.to_test:
print("Testing...")
trainer.test(data.testloader)
print("Testing Finished\n")
if __name__ == "__main__":
main()