forked from microsoft/CNTK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ResNet18_ImageNet1K.cntk
164 lines (138 loc) · 4.37 KB
/
ResNet18_ImageNet1K.cntk
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Node: ResNet-18 with ImageNet -- 18 layers plain ResNet for image classification
# Reference: "Deep Residual Learning for Image Recognition" https://arxiv.org/abs/1512.03385
command = TrainNetwork:Eval
precision = "float"; traceLevel = 1; deviceId = "auto"
RootDir = "."
ConfigDir = "$RootDir$"
DataDir = "$RootDir$"
OutputDir = "$RootDir$/Output"
ModelDir = "$OutputDir$/Models"
MeanDir = "$DataDir$"
modelPath = "$ModelDir$/ResNet_18"
stderr = "$OutputDir$/ResNet_18_BS_out"
parallelTrain = true
TrainNetwork = {
action = "train"
BrainScriptNetworkBuilder = {
include "$ConfigDir$/Macros.bs"
imageShape = 224:224:3 # image dimensions
labelDim = 1000 # number of distinct labels
cMap = 64:128:256:512
bnTimeConst = 4096
model = Sequential(
# conv1 and max pooling
ConvBNReLULayer {cMap[0], (7:7), (2:2), bnTimeConst} :
MaxPoolingLayer {(3:3), stride = 2, pad = true} :
ResNetBasicStack {2, cMap[0], bnTimeConst} :
ResNetBasicInc {cMap[1], (2:2), bnTimeConst} :
ResNetBasic {cMap[1], bnTimeConst} :
ResNetBasicInc {cMap[2], (2:2), bnTimeConst} :
ResNetBasic {cMap[2], bnTimeConst} :
ResNetBasicInc {cMap[3], (2:2), bnTimeConst} :
ResNetBasicStack {2, cMap[3], bnTimeConst} :
# avg pooling
AveragePoolingLayer {(7: 7), stride = 1} :
# FC
LinearLayer {labelDim, init = 'normal', initValueScale = 0.01}
)
# inputs
features = Input {imageShape}
labels = Input {labelDim}
# apply model to features
z = model (features)
# loss and error computation
ce = CrossEntropyWithSoftmax (labels, z)
errs = ClassificationError (labels, z)
top5Errs = ClassificationError (labels, z, topN = 5)
# declare special nodes
featureNodes = (features)
labelNodes = (labels)
criterionNodes = (ce)
evaluationNodes = (errs : top5Errs)
outputNodes = (z)
}
SGD = {
epochSize = 0
minibatchSize = 256
maxEpochs = 90
learningRatesPerMB = 1*30: 0.1*30: 0.01*20: 0.001
momentumPerMB = 0.9
useNAG = true # use Nesterov Momentum
gradUpdateType = "None"
L2RegWeight = 0.0001
dropoutRate = 0
numMBsToShowResult = 100
disableRegInBatchNormalization = true
ParallelTrain = {
parallelizationMethod = "DataParallelSGD"
distributedMBReading = true
parallelizationStartEpoch = 1
DataParallelSGD = {
gradientBits = 32
}
}
}
reader = {
readerType = "ImageReader"
file = "$DataDir$/train_map.txt"
randomize = "Auto"
features = {
width = 224
height = 224
channels = 3
cropType = "RandomArea"
jitterType = "UniRatio"
areaRatio = 0.08:1.0
aspectRatio = 0.75:1.3333
interpolations = "cubic"
brightnessRadius = 0.4
contrastRadius = 0.4
saturationRadius = 0.4
hflip = true
meanFile = "$MeanDir$/ImageNet1K_mean.xml"
}
labels = {
labelDim = 1000
}
}
cvReader = {
readerType = "ImageReader"
file = "$DataDir$/val_map.txt"
randomize = "None"
features = {
width = 224
height = 224
channels = 3
cropType = "Center"
sideRatio = 0.875
interpolations = "cubic"
meanFile = "$MeanDir$/ImageNet1K_mean.xml"
}
labels = {
labelDim = 1000
}
}
}
Eval = {
action = "test"
modelPath = "$modelPath$"
minibatchSize = 200
evalNodeNames = errs:top5Errs
reader={
readerType = "ImageReader"
file = "$DataDir$/val_map.txt"
randomize = "None"
features = {
width = 224
height = 224
channels = 3
cropType = "Center"
sideRatio = 0.875
interpolations = "cubic"
meanFile = "$MeanDir$/ImageNet1K_mean.xml"
}
labels = {
labelDim = 1000
}
}
}