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.
Enabled convo unit tests. Added batch normalization sample.
- Loading branch information
Alexey Kamenev
committed
Dec 15, 2015
1 parent
c54938f
commit 3a0ec41
Showing
9 changed files
with
705 additions
and
461 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
WorkDir=. | ||
ModelDir=$WorkDir$/_out/$ConfigName$ | ||
stderr=$WorkDir$/_out/$ConfigName$ | ||
|
||
ndlMacros=$WorkDir$/Macros.ndl | ||
|
||
precision=float | ||
deviceId=Auto | ||
prefetch=true | ||
parallelTrain=false | ||
|
||
command=Train:AddBNEval:Test | ||
|
||
Train=[ | ||
action=train | ||
modelPath=$ModelDir$/02_BatchNormConv | ||
|
||
NDLNetworkBuilder=[ | ||
networkDescription=$WorkDir$/02_BatchNormConv.ndl | ||
] | ||
|
||
SGD=[ | ||
epochSize=49984 | ||
minibatchSize=64 | ||
learningRatesPerMB=0.03*7:0.01*8:0.003 | ||
#momentumPerMB=0.9*10:0.99 | ||
maxEpochs=10 | ||
#L2RegWeight=0.03 | ||
dropoutRate=0*1:0.5 | ||
] | ||
|
||
reader=[ | ||
readerType=UCIFastReader | ||
file=$WorkDir$/Train.txt | ||
randomize=None | ||
features=[ | ||
dim=3072 | ||
start=1 | ||
] | ||
labels=[ | ||
dim=1 | ||
start=0 | ||
labelDim=10 | ||
labelMappingFile=$WorkDir$/labelsmap.txt | ||
] | ||
] | ||
] | ||
|
||
AddBNEval=[ | ||
action=edit | ||
CurModel=$ModelDir$/02_BatchNormConv | ||
NewModel=$ModelDir$/02_BatchNormConv.Eval | ||
editPath=$WorkDir$/02_BatchNormConv.mel | ||
] | ||
|
||
Test=[ | ||
action=test | ||
modelPath=$ModelDir$/02_BatchNormConv.Eval | ||
# Set minibatch size for testing. | ||
minibatchSize=128 | ||
|
||
NDLNetworkBuilder=[ | ||
networkDescription=$WorkDir$/02_BatchNormConv.ndl | ||
] | ||
|
||
reader=[ | ||
readerType=UCIFastReader | ||
file=$WorkDir$/Test.txt | ||
randomize=None | ||
features=[ | ||
dim=3072 | ||
start=1 | ||
] | ||
labels=[ | ||
dim=1 | ||
start=0 | ||
labelDim=10 | ||
labelMappingFile=$WorkDir$/labelsmap.txt | ||
] | ||
] | ||
] |
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,16 @@ | ||
m=LoadModel($CurModel$, format=cntk) | ||
SetDefaultModel(m) | ||
|
||
ibn_e = BatchNormalization(featScaled, isc, ib, im, iisd, eval = true, spatial = true) | ||
SetNodeInput(conv1.c, 1, ibn_e) | ||
|
||
conv2.bn_e = BatchNormalization(pool1, conv2.sc, conv2.b, conv2.m, conv2.isd, eval = true, spatial = true) | ||
SetNodeInput(conv2.c, 1, conv2.bn_e) | ||
|
||
conv3.bn_e = BatchNormalization(pool2, conv3.sc, conv3.b, conv3.m, conv3.isd, eval = true, spatial = true) | ||
SetNodeInput(conv3.c, 1, conv3.bn_e) | ||
|
||
h1.bn_e = BatchNormalization(pool3, h1.sc, h1.b, h1.m, h1.isd, eval = true, spatial = false) | ||
SetNodeInput(h1.t, 1, h1.bn_e) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
load=ndlMnistMacros | ||
run=DNN | ||
|
||
ndlMnistMacros = [ | ||
ImageW = 32 | ||
ImageH = 32 | ||
ImageC = 3 | ||
LabelDim = 10 | ||
|
||
features = ImageInput(ImageW, ImageH, ImageC, tag = feature) | ||
featOffs = Const(128, rows = 3072) | ||
featScaled = Minus(features, featOffs) | ||
labels = Input(LabelDim, tag = label) | ||
|
||
conv1WScale = 0.0043 | ||
conv1BValue = 0 | ||
conv2WScale = 1.414 | ||
conv2BValue = 0 | ||
conv3WScale = 1.414 | ||
conv3BValue = 0 | ||
fc1WScale = 12 | ||
fc1BValue = 0 | ||
fc2WScale = 1.5 | ||
fc2BValue = 0 | ||
] | ||
|
||
DNN=[ | ||
ib = Parameter(ImageC, 1, init = Uniform, initValueScale = 100) | ||
isc = Parameter(ImageC, 1, init = Uniform, initValueScale = 100) | ||
im = Parameter(ImageC, 1, init = fixedValue, value = 0, needGradient = false) | ||
iisd = Parameter(ImageC, 1, init = fixedValue, value = 0, needGradient = false) | ||
ibn = BatchNormalization(featScaled, isc, ib, im, iisd, eval = false, spatial = true) | ||
|
||
# conv1 | ||
kW1 = 5 | ||
kH1 = 5 | ||
cMap1 = 32 | ||
hStride1 = 1 | ||
vStride1 = 1 | ||
# weight[cMap1, kW1 * kH1 * ImageC] | ||
conv1 = ConvReLULayer(ibn, cMap1, 75, kW1, kH1, hStride1, vStride1, conv1WScale, conv1BValue) | ||
|
||
# pool1 | ||
pool1W = 3 | ||
pool1H = 3 | ||
pool1hStride = 2 | ||
pool1vStride = 2 | ||
pool1 = MaxPooling(conv1, pool1W, pool1H, pool1hStride, pool1vStride) | ||
|
||
# conv2 | ||
kW2 = 5 | ||
kH2 = 5 | ||
cMap2 = 32 | ||
hStride2 = 1 | ||
vStride2 = 1 | ||
# weight[cMap2, kW2 * kH2 * cMap1] | ||
conv2 = ConvBNReLULayer(pool1, cMap1, cMap2, 800, kW2, kH2, hStride2, vStride2, conv2WScale, conv2BValue) | ||
|
||
# pool2 | ||
pool2W = 3 | ||
pool2H = 3 | ||
pool2hStride = 2 | ||
pool2vStride = 2 | ||
pool2 = MaxPooling(conv2, pool2W, pool2H, pool2hStride, pool2vStride) | ||
|
||
# conv3 | ||
kW3 = 5 | ||
kH3 = 5 | ||
cMap3 = 64 | ||
hStride3 = 1 | ||
vStride3 = 1 | ||
# weight[cMap3, kW3 * kH3 * cMap2] | ||
conv3 = ConvBNReLULayer(pool2, cMap2, cMap3, 800, kW3, kH3, hStride3, vStride3, conv3WScale, conv3BValue) | ||
|
||
# pool3 | ||
pool3W = 3 | ||
pool3H = 3 | ||
pool3hStride = 2 | ||
pool3vStride = 2 | ||
pool3 = MaxPooling(conv3, pool3W, pool3H, pool3hStride, pool3vStride) | ||
|
||
hiddenDim = 64 | ||
h1 = DnnBNReLULayer(576, hiddenDim, pool3, fc1WScale, fc1BValue) | ||
h1_d = Dropout(h1) | ||
ol = DNNLastLayer(hiddenDim, labelDim, h1_d, fc2WScale, fc2BValue) | ||
|
||
CE = CrossEntropyWithSoftmax(labels, ol, tag = Criteria) | ||
Err = ErrorPrediction(labels, ol, tag = Eval) | ||
OutputNodes = ol | ||
] | ||
|
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
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
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
Oops, something went wrong.