Skip to content

Commit

Permalink
Merge branch 'master' of https://git.codeplex.com/cntk into fseide/te…
Browse files Browse the repository at this point in the history
…nsors
  • Loading branch information
U-FAREAST\fseide committed Jan 14, 2016
2 parents b3cfd6e + de5be29 commit c89b632
Show file tree
Hide file tree
Showing 65 changed files with 1,265 additions and 325 deletions.
12 changes: 1 addition & 11 deletions Examples/Image/Miscellaneous/CIFAR-10/02_BatchNormConv.mel
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)
12 changes: 7 additions & 5 deletions Examples/Image/Miscellaneous/CIFAR-10/02_BatchNormConv.ndl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ ndlMnistMacros = [
conv3WScale = 1.414
conv3BValue = 0

scScale = 0.03
scValue = 1

expAvg = 1

fc1WScale = 12
fc1BValue = 0
fc2WScale = 1.5
Expand All @@ -35,7 +37,7 @@ DNN=[
hStride1 = 1
vStride1 = 1
# weight[cMap1, kW1 * kH1 * ImageC]
conv1 = ConvBNReLULayer(featScaled, cMap1, 75, kW1, kH1, hStride1, vStride1, conv1WScale, conv1BValue, scScale)
conv1 = ConvBNReLULayer(featScaled, cMap1, 75, kW1, kH1, hStride1, vStride1, conv1WScale, conv1BValue, scValue, expAvg)

# pool1
pool1W = 3
Expand All @@ -51,7 +53,7 @@ DNN=[
hStride2 = 1
vStride2 = 1
# weight[cMap2, kW2 * kH2 * cMap1]
conv2 = ConvBNReLULayer(pool1, cMap2, 800, kW2, kH2, hStride2, vStride2, conv2WScale, conv2BValue, scScale)
conv2 = ConvBNReLULayer(pool1, cMap2, 800, kW2, kH2, hStride2, vStride2, conv2WScale, conv2BValue, scValue, expAvg)

# pool2
pool2W = 3
Expand All @@ -67,7 +69,7 @@ DNN=[
hStride3 = 1
vStride3 = 1
# weight[cMap3, kW3 * kH3 * cMap2]
conv3 = ConvBNReLULayer(pool2, cMap3, 800, kW3, kH3, hStride3, vStride3, conv3WScale, conv3BValue, scScale)
conv3 = ConvBNReLULayer(pool2, cMap3, 800, kW3, kH3, hStride3, vStride3, conv3WScale, conv3BValue, scValue, expAvg)

# pool3
pool3W = 3
Expand All @@ -77,7 +79,7 @@ DNN=[
pool3 = MaxPooling(conv3, pool3W, pool3H, pool3hStride, pool3vStride, imageLayout = "cudnn")

hiddenDim = 64
h1 = DnnBNReLULayer(576, hiddenDim, pool3, fc1WScale, fc1BValue)
h1 = DnnBNReLULayer(576, hiddenDim, pool3, fc1WScale, fc1BValue, scValue, expAvg)
ol = DNNLastLayer(hiddenDim, labelDim, h1, fc2WScale, fc2BValue)

CE = CrossEntropyWithSoftmax(labels, ol, tag = Criteria)
Expand Down
8 changes: 4 additions & 4 deletions Examples/Image/Miscellaneous/CIFAR-10/03_ResNet.config
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Train=[
minibatchSize=128
learningRatesPerMB=0.1*80:0.01*40:0.001
momentumPerMB=0.9
maxEpochs=10
maxEpochs=160
L2RegWeight=0.0001
dropoutRate=0

Expand All @@ -57,10 +57,10 @@ Train=[
height=32
channels=3
cropType=Random
cropRatio=1
cropRatio=0.8
jitterType=UniRatio
interpolations=Linear
#meanFile=
meanFile=$ConfigDir$/CIFAR-10_mean.xml
]
labels=[
labelDim=10
Expand Down Expand Up @@ -97,7 +97,7 @@ Test=[
cropRatio=1
jitterType=UniRatio
interpolations=Linear
#meanFile=
meanFile=$ConfigDir$/CIFAR-10_mean.xml
]
labels=[
labelDim=10
Expand Down
48 changes: 1 addition & 47 deletions Examples/Image/Miscellaneous/CIFAR-10/03_ResNet.mel
Original file line number Diff line number Diff line change
@@ -1,52 +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_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")
SetNodeInput(rn3_1.p, 0, rn3_1.bn2_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)
39 changes: 20 additions & 19 deletions Examples/Image/Miscellaneous/CIFAR-10/03_ResNet.ndl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ LocalMacros = [
LabelDim = 10

features = ImageInput(ImageW, ImageH, ImageC, tag = feature, imageLayout = "cudnn")
featOffs = Const(128)
featScaled = Minus(features, featOffs)
labels = Input(LabelDim, tag = label)

convWScale = 7.07
convBValue = 0
fc1WScale = 12
fc1BValue = 0

scValue = 0.03
scValue = 1

expAvg = 1

kW = 3
kH = 3
Expand All @@ -29,33 +29,34 @@ LocalMacros = [
]

DNN=[
conv1WScale = 0.26
cMap1 = 16
conv1 = ConvBNReLULayer(featScaled, cMap1, 27, kW, kH, hStride1, vStride1, convWScale, convBValue, scValue)
conv1 = ConvBNReLULayer(features, cMap1, 27, kW, kH, hStride1, vStride1, conv1WScale, convBValue, scValue, expAvg)

rn1_1 = ResNetNode2(conv1, cMap1, 144, kW, kH, convWScale, convBValue, scValue)
rn1_2 = ResNetNode2(rn1_1, cMap1, 144, kW, kH, convWScale, convBValue, scValue)
rn1_3 = ResNetNode2(rn1_2, cMap1, 144, kW, kH, convWScale, convBValue, scValue)
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)

cMap2 = 32
rn2_1_Wproj = Parameter(cMap2, cMap1, init = fromFile, initFromFilePath = "$Proj16to32Filename$", needGradient = false)
rn2_1 = ResNetNode2Inc(rn1_3, cMap2, 144, 288, kW, kH, convWScale, convBValue, scValue, rn2_1_Wproj)
rn2_2 = ResNetNode2(rn2_1, cMap2, 288, kW, kH, convWScale, convBValue, scValue)
rn2_3 = ResNetNode2(rn2_2, cMap2, 288, kW, kH, convWScale, convBValue, scValue)
rn2_1 = ResNetNode2Inc(rn1_3, 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)

cMap3 = 64
rn3_1_Wproj = Parameter(cMap3, cMap2, init = fromFile, initFromFilePath = "$Proj32to64Filename$", needGradient = false)
rn3_1 = ResNetNode2Inc(rn2_3, cMap3, 288, 576, kW, kH, convWScale, convBValue, scValue, rn3_1_Wproj)
rn3_2 = ResNetNode2(rn3_1, cMap3, 576, kW, kH, convWScale, convBValue, scValue)
rn3_3 = ResNetNode2(rn3_2, cMap3, 576, kW, kH, convWScale, convBValue, scValue)
rn3_1 = ResNetNode2Inc(rn2_3, 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)

# pool
poolW = 3
poolH = 3
poolhStride = 2
poolvStride = 2
# Global average pooling
poolW = 8
poolH = 8
poolhStride = 1
poolvStride = 1
pool = AveragePooling(rn3_3, poolW, poolH, poolhStride, poolvStride, imageLayout = "cudnn")

ol = DnnLastLayer(576, labelDim, pool, fc1WScale, fc1BValue)
ol = DnnLastLayer(cMap3, labelDim, pool, fc1WScale, fc1BValue)

CE = CrossEntropyWithSoftmax(labels, ol, tag = Criteria)
Err = ErrorPrediction(labels, ol, tag = Eval)
Expand Down
106 changes: 106 additions & 0 deletions Examples/Image/Miscellaneous/CIFAR-10/04_ResNet_56.config
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
]
]
]
Loading

0 comments on commit c89b632

Please sign in to comment.