-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtrain.py
101 lines (94 loc) · 3.11 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from os import path as osp
from argparse import Namespace
import sys
from torch import nn, optim
from torchvision import transforms
from beauty import Task, networks, metrics, lr_schedulers, datasets
if __name__ == '__main__':
gpus = int(sys.argv[1])
task_name = sys.argv[2]
config = Namespace(
data=Namespace(
train=Namespace(
dataset=datasets.ImageNet,
config=Namespace(
data_dir=(
'/mnt/lustre/share/images/train/'
),
data_list_path=(
'/mnt/lustre/share/images/meta/train.txt'
),
transforms=[
Namespace(
transform=datasets.transforms.ToColor,
config=Namespace()
),
Namespace(
transform=transforms.Resize,
config=Namespace(size=(320, 320))
),
Namespace(
transform=transforms.ToTensor,
config=Namespace()
)
]
),
batch_size=gpus * 32
),
val=Namespace(
dataset=datasets.ImageNet,
config=Namespace(
data_dir=(
'/mnt/lustre/share/images/val/'
),
data_list_path=(
'/mnt/lustre/share/images/meta/val.txt'
),
transforms=[
Namespace(
transform=datasets.transforms.ToColor,
config=Namespace()
),
Namespace(
transform=transforms.Resize,
config=Namespace(size=(320, 320))
),
Namespace(
transform=transforms.ToTensor,
config=Namespace()
)
]
),
batch_size=gpus * 32
)
),
model=Namespace(
network=networks.BeautyNet,
feature_extractor=networks.feature_extractors.ResNet50,
classifier=networks.classifiers.SoftmaxClassifier,
class_count=1000,
weight_decay=5e-4,
loss=nn.CrossEntropyLoss
),
training=Namespace(
epochs=1000
),
optimizer=Namespace(
optimizer=optim.Adam,
config=Namespace(
betas=(0.9, 0.99)
)
),
lr=Namespace(
lr=1e-3,
lr_scheduler=lr_schedulers.ConstantLr,
config=Namespace()
),
log=Namespace(
dir=osp.join('logs', task_name),
interval=1,
metrics=[metrics.Accuracy]
)
)
task = Task(task_name, config)
task.train()