forked from microsoft/CNTK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added BN eval mode to MEL. Updated samples.
- Loading branch information
Alexey Kamenev
committed
Jan 12, 2016
1 parent
9e25b7e
commit 92e8a4d
Showing
10 changed files
with
306 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
m=LoadModel($CurModel$, format=cntk) | ||
SetDefaultModel(m) | ||
|
||
conv1.bn_e = BatchNormalization(conv1.c, conv1.sc, conv1.b, conv1.m, conv1.isd, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(conv1.y, 0, conv1.bn_e) | ||
|
||
conv2.bn_e = BatchNormalization(conv2.c, conv2.sc, conv2.b, conv2.m, conv2.isd, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(conv2.y, 0, conv2.bn_e) | ||
|
||
conv3.bn_e = BatchNormalization(conv3.c, conv3.sc, conv3.b, conv3.m, conv3.isd, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(conv3.y, 0, conv3.bn_e) | ||
|
||
h1.bn_e = BatchNormalization(h1.t, h1.sc, h1.b, h1.m, h1.isd, eval = true, spatial = false) | ||
SetNodeInput(h1.y, 0, h1.bn_e) | ||
SetPropertyForSubTree(CE, batchNormEvalMode, true) | ||
|
||
SaveModel(m, $NewModel$, format=cntk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,6 @@ | ||
m=LoadModel($CurModel$, format=cntk) | ||
SetDefaultModel(m) | ||
|
||
conv1.bn_e = BatchNormalization(conv1.c, conv1.sc, conv1.b, conv1.m, conv1.isd, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(conv1.y, 0, conv1.bn_e) | ||
|
||
rn1_1.bn1_e = BatchNormalization(rn1_1.c1, rn1_1.sc1, rn1_1.b1, rn1_1.m1, rn1_1.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn1_1.y1, 0, rn1_1.bn1_e) | ||
rn1_1.bn2_e = BatchNormalization(rn1_1.c2, rn1_1.sc2, rn1_1.b2, rn1_1.m2, rn1_1.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn1_1.p, 0, rn1_1.bn2_e) | ||
|
||
rn1_2.bn1_e = BatchNormalization(rn1_2.c1, rn1_2.sc1, rn1_2.b1, rn1_2.m1, rn1_2.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn1_2.y1, 0, rn1_2.bn1_e) | ||
rn1_2.bn2_e = BatchNormalization(rn1_2.c2, rn1_2.sc2, rn1_2.b2, rn1_2.m2, rn1_2.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn1_2.p, 0, rn1_2.bn2_e) | ||
|
||
rn1_3.bn1_e = BatchNormalization(rn1_3.c1, rn1_3.sc1, rn1_3.b1, rn1_3.m1, rn1_3.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn1_3.y1, 0, rn1_3.bn1_e) | ||
rn1_3.bn2_e = BatchNormalization(rn1_3.c2, rn1_3.sc2, rn1_3.b2, rn1_3.m2, rn1_3.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn1_3.p, 0, rn1_3.bn2_e) | ||
|
||
rn2_1.bn1_e = BatchNormalization(rn2_1.c1, rn2_1.sc1, rn2_1.b1, rn2_1.m1, rn2_1.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_1.y1, 0, rn2_1.bn1_e) | ||
rn2_1.bn2_e = BatchNormalization(rn2_1.c2, rn2_1.sc2, rn2_1.b2, rn2_1.m2, rn2_1.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_1.p, 0, rn2_1.bn2_e) | ||
#rn2_1.bn_proj_e = BatchNormalization(rn2_1.c_proj, rn2_1.sc_proj, rn2_1.b_proj, rn2_1.m_proj, rn2_1.isd_proj, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_1.p, 0, rn2_1.bn2_e) | ||
#SetNodeInput(rn2_1.p, 1, rn2_1.bn_proj_e) | ||
|
||
rn2_2.bn1_e = BatchNormalization(rn2_2.c1, rn2_2.sc1, rn2_2.b1, rn2_2.m1, rn2_2.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_2.y1, 0, rn2_2.bn1_e) | ||
rn2_2.bn2_e = BatchNormalization(rn2_2.c2, rn2_2.sc2, rn2_2.b2, rn2_2.m2, rn2_2.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_2.p, 0, rn2_2.bn2_e) | ||
|
||
rn2_3.bn1_e = BatchNormalization(rn2_3.c1, rn2_3.sc1, rn2_3.b1, rn2_3.m1, rn2_3.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_3.y1, 0, rn2_3.bn1_e) | ||
rn2_3.bn2_e = BatchNormalization(rn2_3.c2, rn2_3.sc2, rn2_3.b2, rn2_3.m2, rn2_3.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn2_3.p, 0, rn2_3.bn2_e) | ||
|
||
rn3_1.bn1_e = BatchNormalization(rn3_1.c1, rn3_1.sc1, rn3_1.b1, rn3_1.m1, rn3_1.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn3_1.y1, 0, rn3_1.bn1_e) | ||
rn3_1.bn2_e = BatchNormalization(rn3_1.c2, rn3_1.sc2, rn3_1.b2, rn3_1.m2, rn3_1.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
#rn3_1.bn_proj_e = BatchNormalization(rn3_1.c_proj, rn3_1.sc_proj, rn3_1.b_proj, rn3_1.m_proj, rn3_1.isd_proj, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn3_1.p, 0, rn3_1.bn2_e) | ||
#SetNodeInput(rn3_1.p, 1, rn3_1.bn_proj_e) | ||
|
||
rn3_2.bn1_e = BatchNormalization(rn3_2.c1, rn3_2.sc1, rn3_2.b1, rn3_2.m1, rn3_2.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn3_2.y1, 0, rn3_2.bn1_e) | ||
rn3_2.bn2_e = BatchNormalization(rn3_2.c2, rn3_2.sc2, rn3_2.b2, rn3_2.m2, rn3_2.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn3_2.p, 0, rn3_2.bn2_e) | ||
|
||
rn3_3.bn1_e = BatchNormalization(rn3_3.c1, rn3_3.sc1, rn3_3.b1, rn3_3.m1, rn3_3.isd1, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn3_3.y1, 0, rn3_3.bn1_e) | ||
rn3_3.bn2_e = BatchNormalization(rn3_3.c2, rn3_3.sc2, rn3_3.b2, rn3_3.m2, rn3_3.isd2, eval = true, spatial = true, imageLayout = "cudnn") | ||
SetNodeInput(rn3_3.p, 0, rn3_3.bn2_e) | ||
SetPropertyForSubTree(CE, batchNormEvalMode, true) | ||
|
||
SaveModel(m, $NewModel$, format=cntk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
Examples/Image/Miscellaneous/CIFAR-10/04_ResNet_56.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
RootDir = "." | ||
|
||
ConfigDir = "$RootDir$" | ||
DataDir = "$RootDir$" | ||
OutputDir = "$RootDir$/Output" | ||
ModelDir = "$OutputDir$/Models" | ||
|
||
ndlMacros=$ConfigDir$/Macros.ndl | ||
|
||
precision=float | ||
deviceId=Auto | ||
prefetch=true | ||
parallelTrain=false | ||
|
||
command=Train:AddBNEval:Test | ||
|
||
stderr=$OutputDir$/04_ResNet_56 | ||
traceLevel=1 | ||
numMBsToShowResult=200 | ||
|
||
Proj16to32Filename = $ConfigDir$/16to32.txt | ||
Proj32to64Filename = $ConfigDir$/32to64.txt | ||
|
||
Train=[ | ||
action=train | ||
modelPath=$ModelDir$/04_ResNet_56 | ||
|
||
NDLNetworkBuilder=[ | ||
networkDescription=$ConfigDir$/04_ResNet_56.ndl | ||
] | ||
|
||
SGD=[ | ||
epochSize=0 | ||
minibatchSize=128 | ||
learningRatesPerMB=0.1*80:0.01*40:0.001 | ||
momentumPerMB=0.9 | ||
maxEpochs=1 | ||
L2RegWeight=0.0001 | ||
dropoutRate=0 | ||
|
||
ParallelTrain=[ | ||
parallelizationMethod=DataParallelSGD | ||
distributedMBReading=true | ||
parallelizationStartEpoch=1 | ||
DataParallelSGD=[ | ||
gradientBits=1 | ||
] | ||
] | ||
] | ||
|
||
reader=[ | ||
readerType=ImageReader | ||
file=$DataDir$/train_map.txt | ||
randomize=Auto | ||
features=[ | ||
width=32 | ||
height=32 | ||
channels=3 | ||
cropType=Random | ||
cropRatio=0.8 | ||
jitterType=UniRatio | ||
interpolations=Linear | ||
meanFile=$ConfigDir$/CIFAR-10_mean.xml | ||
] | ||
labels=[ | ||
labelDim=10 | ||
] | ||
] | ||
] | ||
|
||
AddBNEval=[ | ||
action=edit | ||
CurModel=$ModelDir$/04_ResNet_56 | ||
NewModel=$ModelDir$/04_ResNet_56.Eval | ||
editPath=$ConfigDir$/03_ResNet.mel | ||
] | ||
|
||
Test=[ | ||
action=test | ||
modelPath=$ModelDir$/04_ResNet_56 | ||
# Set minibatch size for testing. | ||
minibatchSize=512 | ||
|
||
NDLNetworkBuilder=[ | ||
networkDescription=$ConfigDir$/04_ResNet_56.ndl | ||
] | ||
|
||
reader=[ | ||
readerType=ImageReader | ||
file=$DataDir$/test_map.txt | ||
randomize=Auto | ||
features=[ | ||
width=32 | ||
height=32 | ||
channels=3 | ||
cropType=Center | ||
cropRatio=1 | ||
jitterType=UniRatio | ||
interpolations=Linear | ||
meanFile=$ConfigDir$/CIFAR-10_mean.xml | ||
] | ||
labels=[ | ||
labelDim=10 | ||
] | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
load=LocalMacros | ||
run=DNN | ||
|
||
LocalMacros = [ | ||
ImageW = 32 | ||
ImageH = 32 | ||
ImageC = 3 | ||
LabelDim = 10 | ||
|
||
features = ImageInput(ImageW, ImageH, ImageC, tag = feature, imageLayout = "cudnn") | ||
labels = Input(LabelDim, tag = label) | ||
|
||
convWScale = 7.07 | ||
convBValue = 0 | ||
fc1WScale = 12 | ||
fc1BValue = 0 | ||
|
||
scValue = 1 | ||
|
||
expAvg = 1 | ||
|
||
kW = 3 | ||
kH = 3 | ||
|
||
hStride1 = 1 | ||
vStride1 = 1 | ||
hStride2 = 2 | ||
vStride2 = 2 | ||
] | ||
|
||
DNN=[ | ||
conv1WScale = 0.26 | ||
cMap1 = 16 | ||
conv1 = ConvBNReLULayer(features, cMap1, 27, kW, kH, hStride1, vStride1, conv1WScale, convBValue, scValue, expAvg) | ||
|
||
rn1_1 = ResNetNode2(conv1, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_2 = ResNetNode2(rn1_1, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_3 = ResNetNode2(rn1_2, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_4 = ResNetNode2(rn1_3, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_5 = ResNetNode2(rn1_4, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_6 = ResNetNode2(rn1_5, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_7 = ResNetNode2(rn1_6, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_8 = ResNetNode2(rn1_7, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_9 = ResNetNode2(rn1_8, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_10= ResNetNode2(rn1_9, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_11= ResNetNode2(rn1_10, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_12= ResNetNode2(rn1_11, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_13= ResNetNode2(rn1_12, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_14= ResNetNode2(rn1_13, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_15= ResNetNode2(rn1_14, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_16= ResNetNode2(rn1_15, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_17= ResNetNode2(rn1_16, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn1_18= ResNetNode2(rn1_17, cMap1, 144, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
|
||
cMap2 = 32 | ||
rn2_1_Wproj = Parameter(cMap2, cMap1, init = fromFile, initFromFilePath = "$Proj16to32Filename$", needGradient = false) | ||
rn2_1 = ResNetNode2Inc(rn1_18, cMap2, 144, 288, kW, kH, convWScale, convBValue, scValue, expAvg, rn2_1_Wproj) | ||
rn2_2 = ResNetNode2(rn2_1, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_3 = ResNetNode2(rn2_2, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_4 = ResNetNode2(rn2_3, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_5 = ResNetNode2(rn2_4, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_6 = ResNetNode2(rn2_5, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_7 = ResNetNode2(rn2_6, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_8 = ResNetNode2(rn2_7, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_9 = ResNetNode2(rn2_8, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_10= ResNetNode2(rn2_9, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_11= ResNetNode2(rn2_10, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_12= ResNetNode2(rn2_11, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_13= ResNetNode2(rn2_12, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_14= ResNetNode2(rn2_13, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_15= ResNetNode2(rn2_14, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_16= ResNetNode2(rn2_15, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_17= ResNetNode2(rn2_16, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn2_18= ResNetNode2(rn2_17, cMap2, 288, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
|
||
cMap3 = 64 | ||
rn3_1_Wproj = Parameter(cMap3, cMap2, init = fromFile, initFromFilePath = "$Proj32to64Filename$", needGradient = false) | ||
rn3_1 = ResNetNode2Inc(rn2_18, cMap3, 288, 576, kW, kH, convWScale, convBValue, scValue, expAvg, rn3_1_Wproj) | ||
rn3_2 = ResNetNode2(rn3_1, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_3 = ResNetNode2(rn3_2, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_4 = ResNetNode2(rn3_3, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_5 = ResNetNode2(rn3_4, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_6 = ResNetNode2(rn3_5, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_7 = ResNetNode2(rn3_6, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_8 = ResNetNode2(rn3_7, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_9 = ResNetNode2(rn3_8, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_10= ResNetNode2(rn3_9, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_11= ResNetNode2(rn3_10, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_12= ResNetNode2(rn3_11, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_13= ResNetNode2(rn3_12, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_14= ResNetNode2(rn3_13, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_15= ResNetNode2(rn3_14, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_16= ResNetNode2(rn3_15, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_17= ResNetNode2(rn3_16, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
rn3_18= ResNetNode2(rn3_17, cMap3, 576, kW, kH, convWScale, convBValue, scValue, expAvg) | ||
|
||
# Global average pooling | ||
poolW = 8 | ||
poolH = 8 | ||
poolhStride = 1 | ||
poolvStride = 1 | ||
pool = AveragePooling(rn3_18, poolW, poolH, poolhStride, poolvStride, imageLayout = "cudnn") | ||
|
||
ol = DnnLastLayer(cMap3, labelDim, pool, fc1WScale, fc1BValue) | ||
|
||
CE = CrossEntropyWithSoftmax(labels, ol, tag = Criteria) | ||
Err = ErrorPrediction(labels, ol, tag = Eval) | ||
OutputNodes = ol | ||
] | ||
|
Oops, something went wrong.