add brainscript version, update configs.
This commit is contained in:
Родитель
e4bcf0f1b5
Коммит
fc560474bb
|
@ -0,0 +1,196 @@
|
|||
makeMode = false
|
||||
|
||||
command=Train
|
||||
#command=Test
|
||||
#command=Write
|
||||
|
||||
deviceId = "Auto"
|
||||
precision = "float"
|
||||
parallelTrain = "false"
|
||||
traceLevel = 1
|
||||
|
||||
rootDir = "." ;
|
||||
dataDir = "$rootDir$/data/" ;
|
||||
outputDir = "$rootDir$/Output"
|
||||
modelDir = "$outputDir$"
|
||||
|
||||
modelPath = "$modelDir$/Fast-RCNN"
|
||||
stderr = "$outputDir$/Fast-RCNN.log"
|
||||
|
||||
ImageH = 1000
|
||||
ImageW = 1000
|
||||
ImageC = 3
|
||||
|
||||
NumLabels = 21
|
||||
|
||||
NumTrainROIs = 64
|
||||
TrainROIDim = 256 # $NumTrainROIs$ * 4
|
||||
TrainROILabelDim = 1344 # $NumTrainROIs$ * $NumLabels$
|
||||
|
||||
NumTestROIs = 200
|
||||
TestROIDim = 800
|
||||
TestROILabelDim = 4200
|
||||
|
||||
Train = {
|
||||
action = "train"
|
||||
|
||||
BrainScriptNetworkBuilder = {
|
||||
ROIPooling (input, ROIs, shape) = new ComputationNode { operation = 'ROIPooling' ; inputs = (ROIs:input) ; H = shape[1] ; W = shape[0] ; imageLayout = "cudnn" ; tag='' /*plus the function args*/ }
|
||||
CrossEntropyWithSoftmaxND (y, z, axis=0) = ReduceLogSum (z, axis=axis) - ReduceSum (y .* z, axis=axis)
|
||||
# account for all wrong predictions, max 1 per instance
|
||||
MyClassificationErrorND (out, labels, axis=1, tag='') = {
|
||||
axmax = ReduceMax (out, axis=axis) # max value along competition axis
|
||||
pred = Equal(out, axmax) # 1 for all values that are max
|
||||
wrongPred = NotEqual (labels, pred) # look up all wrong predictions {label index}
|
||||
axErr = ReduceSum(wrongPred, axis=axis) # sum up wrong predictions along competition axis
|
||||
capErr = GreaterEqual (axErr, Constant(1)) # only count maximally one error per prediction
|
||||
err = ReduceMean (capErr, tag=tag) # average into a single number per sample
|
||||
}.err
|
||||
|
||||
imageShape = $ImageH$:$ImageW$:$ImageC$ # 500:500:3
|
||||
labelShape = $NumLabels$:$NumTrainROIs$ # 21:64
|
||||
ROIShape = $TrainROIDim$ # 256
|
||||
|
||||
network = BS.Network.Load ("AlexNet.89")
|
||||
pool1 = BS.Network.CloneFunction(network.features, network.pool1, parameters="constant")
|
||||
middle = BS.Network.CloneFunction(network.pool1, network.conv5_y)
|
||||
fcLayers = BS.Network.CloneFunction(network.pool3, network.h2_d)
|
||||
|
||||
model (features, rois) = {
|
||||
featNorm = features - Constant (114)
|
||||
pool1Out = pool1 (featNorm)
|
||||
conv5Out = middle (pool1Out)
|
||||
roiOut = ROIPooling (conv5Out, rois, (6:6))
|
||||
fcOut = fcLayers (roiOut)
|
||||
#z = LinearLayer { 21, init='gaussian', initValueScale=0.01 } (fcOut)
|
||||
fW = ParameterTensor((21:4096), init='gaussian', initValueScale=0.01)
|
||||
fb = ParameterTensor(21, init='zero')
|
||||
ft = Times(fW, fcOut)
|
||||
z = Plus(ft, fb)
|
||||
}.z
|
||||
|
||||
features = Input (imageShape)
|
||||
roiLabels = Input (labelShape)
|
||||
rois = Input (ROIShape)
|
||||
|
||||
z = model (features, rois)
|
||||
|
||||
ce = CrossEntropyWithSoftmaxND (roiLabels, z, axis=1)
|
||||
errs = MyClassificationErrorND(z, roiLabels, axis=1)
|
||||
|
||||
featureNodes = (features:rois)
|
||||
labelNodes = (roiLabels)
|
||||
criterionNodes = (ce)
|
||||
evaluationNodes = (errs)
|
||||
outputNodes = (z)
|
||||
}
|
||||
|
||||
SGD = {
|
||||
epochSize=0
|
||||
minibatchSize=2
|
||||
maxEpochs=1 # !!!! 15
|
||||
learningRatesPerMB=0.0001*5:0.0001
|
||||
momentumPerMB=0*5:0.9
|
||||
L2RegWeight=0.0001 #0.0005
|
||||
dropoutRate=0.5
|
||||
|
||||
numMBsToShowResult=50
|
||||
}
|
||||
|
||||
reader = {
|
||||
randomize = false
|
||||
verbosity = 2
|
||||
deserializers = ({
|
||||
type = "CNTKTextFormatDeserializer" ; module = "CNTKTextFormatReader"
|
||||
file = "$dataDir$/tv2012pad.rois.txt"
|
||||
input = { rois = { dim = $TrainROIDim$ ; format = "dense" } }
|
||||
}:{
|
||||
type = "CNTKTextFormatDeserializer" ; module = "CNTKTextFormatReader"
|
||||
file = "$dataDir$/tv2012pad.roilabels.txt"
|
||||
input = { roiLabels = { dim = $TrainROILabelDim$ ; format = "dense" } }
|
||||
}:{
|
||||
type = "ImageDeserializer" ; module = "ImageReader"
|
||||
file="$dataDir$/tv2012pad.txt"
|
||||
input = {
|
||||
features = { transforms = (
|
||||
{ type = "ScaleSide" ; target = $ImageW$ ; side = "max" }:
|
||||
{ type = "Pad" ; width = $ImageW$ ; height = $ImageH$; channels = $ImageC$; value = 114 }:
|
||||
#{ type = "Mean" ; meanFile = "$rootDir$/ImageNet500_mean.xml" }
|
||||
{ type = "Transpose" }
|
||||
)}
|
||||
ignored={labelDim=1000}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Test={
|
||||
action="test"
|
||||
minibatchSize=1
|
||||
|
||||
# use for wrtie action
|
||||
# action="write"
|
||||
# outputPath="$OutputDir$/write_bs03_model02"
|
||||
|
||||
BrainScriptNetworkBuilder = {
|
||||
CrossEntropyWithSoftmaxND (y, z, axis=0) = ReduceLogSum (z, axis=axis) - ReduceSum (y .* z, axis=axis)
|
||||
# account for all wrong predictions, max 1 per instance
|
||||
MyClassificationErrorND (out, labels, axis=1, tag='') = {
|
||||
axmax = ReduceMax (out, axis=axis) # max value along competition axis
|
||||
pred = Equal(out, axmax) # 1 for all values that are max
|
||||
wrongPred = NotEqual (labels, pred) # look up all wrong predictions {label index}
|
||||
axErr = ReduceSum(wrongPred, axis=axis) # sum up wrong predictions along competition axis
|
||||
capErr = GreaterEqual (axErr, Constant(1)) # only count maximally one error per prediction
|
||||
err = ReduceMean (capErr, tag=tag) # average into a single number per sample
|
||||
}.err
|
||||
|
||||
imageShape = $ImageH$:$ImageW$:$ImageC$ # 1000:1000:3
|
||||
labelShape = $NumLabels$:$NumTestROIs$ # 21:200
|
||||
ROIShape = $TestROIDim$ # 800
|
||||
|
||||
# load network
|
||||
network = BS.Network.Load ("$modelDir$/RCNN-test02.bs")
|
||||
clonedNet = BS.Network.CloneFunction ((network.features:network.rois), { z = network.z }, parameters="constant")
|
||||
|
||||
features = Input (imageShape)
|
||||
roiLabels = Input (labelShape)
|
||||
rois = Input (ROIShape)
|
||||
|
||||
z = clonedNet(features, rois).z
|
||||
|
||||
ce = CrossEntropyWithSoftmaxND (roiLabels, z, axis=1)
|
||||
errs = MyClassificationErrorND(z, roiLabels, axis=1)
|
||||
|
||||
featureNodes = (features:rois)
|
||||
labelNodes = (roiLabels)
|
||||
criterionNodes = (ce)
|
||||
evaluationNodes = (errs)
|
||||
outputNodes = (z)
|
||||
}
|
||||
|
||||
reader = {
|
||||
randomize = false
|
||||
verbosity = 2
|
||||
deserializers = ({
|
||||
type = "CNTKTextFormatDeserializer" ; module = "CNTKTextFormatReader"
|
||||
file = "$dataDir$/test2007pad_all.rois.txt"
|
||||
input = { rois = { dim = $TestROIDim$ ; format = "dense" } }
|
||||
}:{
|
||||
type = "CNTKTextFormatDeserializer" ; module = "CNTKTextFormatReader"
|
||||
file = "$dataDir$/test2007pad_all.roilabels.txt"
|
||||
input = { roiLabels = { dim = $TestROILabelDim$ : format = "dense" } }
|
||||
}:{
|
||||
type = "ImageDeserializer" ; module = "ImageReader"
|
||||
file="$dataDir$/test2007pad_all.txt"
|
||||
input = {
|
||||
features = { transforms = (
|
||||
{ type = "ScaleSide" ; target = $ImageW$ ; side = "max" }:
|
||||
{ type = "Pad" ; width = $ImageW$ ; height = $ImageH$; channels = $ImageC$; value = 114 }:
|
||||
#{ type = "Mean" ; meanFile = "$rootDir$/ImageNet500_mean.xml" }
|
||||
{ type = "Transpose" }
|
||||
)}
|
||||
ignored={labelDim=1000}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
m1 = LoadModel("$curModel$", format="cntk")
|
||||
SetDefaultModel(m1)
|
||||
|
||||
fc3WScale = 0.01
|
||||
fc3BValue = 0
|
||||
|
||||
roiDim = $TrainROIDim$
|
||||
roiLabelDim = $TrainROILabelDim$
|
||||
LabelDim = $LabelDim$
|
||||
|
||||
# replace the pooling layer
|
||||
rois = Input(roiDim, tag="feature")
|
||||
roi = ROIPooling(rois, conv5.y, 6, 6)
|
||||
|
||||
# 9216 = 6 * 6 * 256--the size of each ROI.
|
||||
rshp = Reshape(roi, 9216, imageWidth=6, imageHeight=6, imageChannels=256, imageLayout="CHW")
|
||||
SetInput(h1.t, 1, rshp)
|
||||
|
||||
# replace the labels
|
||||
roiLabels = Input(roiLabelDim, tag="label")
|
||||
rshpROI = Reshape(roiLabels, LabelDim, imageWidth=LabelDim, imageHeight=1, imagechannels=1, imageLayout="CHW")
|
||||
rshpLabels = ReconcileDynamicAxis(rshpROI, rshp)
|
||||
|
||||
SetInput(Err, 0, rshpLabels)
|
||||
SetInput(CE, 0, rshpLabels)
|
||||
DeleteNode(labels)
|
||||
|
||||
# replace the last layer
|
||||
newL = DnnLastLayer(4096, 21, h2_d, fc3WScale, fc3BValue)
|
||||
SetInput(CE, 1, newL.z)
|
||||
SetInput(Err, 1, newL.z)
|
||||
SetProperty(newL.z, "output", "true")
|
||||
|
||||
# remove replaced nodes
|
||||
DeleteNode(OutputNodes.z)
|
||||
DeleteNode(OutputNodes.t)
|
||||
DeleteNode(OutputNodes.b)
|
||||
DeleteNode(OutputNodes.W)
|
||||
DeleteNode(pool3)
|
||||
|
||||
Rename(newL.*, OutputNodes.*)
|
||||
|
||||
# turn off gradient updates for first conv layer.
|
||||
SetProperty(pool1, "NeedsGradient", "false")
|
||||
SetProperty(conv1.W, "NeedsGradient", "false")
|
||||
SetProperty(conv1.b, "NeedsGradient", "false")
|
||||
SetProperty(conv1.c, "NeedsGradient", "false")
|
||||
SetProperty(conv1.z, "NeedsGradient", "false")
|
||||
SetProperty(conv1.y, "NeedsGradient", "false")
|
||||
|
||||
SetProperty(pool1, "learningRateMultiplier", "0")
|
||||
SetProperty(conv1.W, "learningRateMultiplier", "0")
|
||||
SetProperty(conv1.b, "learningRateMultiplier", "0")
|
||||
SetProperty(conv1.c, "learningRateMultiplier", "0")
|
||||
SetProperty(conv1.z, "learningRateMultiplier", "0")
|
||||
SetProperty(conv1.y, "learningRateMultiplier", "0")
|
||||
|
||||
SaveModel(m1, "$newModel$", format="cntk")
|
|
@ -1,109 +0,0 @@
|
|||
load=ndlMacros
|
||||
run=DNN
|
||||
|
||||
ndlMacros = [
|
||||
ImageW = 224
|
||||
ImageH = 224
|
||||
ImageC = 3
|
||||
|
||||
roiDim = 8000
|
||||
rois = Input(roiDim, tag="feature")
|
||||
|
||||
features = ImageInput(ImageW, ImageH, ImageC, tag = feature, imageLayout = "cudnn")
|
||||
roiLabels = Input(42000, tag = "label")
|
||||
|
||||
conv1WScale = 0.95
|
||||
conv1BValue = 0
|
||||
conv2WScale = 2
|
||||
conv2BValue = 1
|
||||
conv3WScale = 2.07
|
||||
conv3BValue = 0
|
||||
conv4WScale = 2.9
|
||||
conv4BValue = 1
|
||||
conv5WScale = 2.4
|
||||
conv5BValue = 1
|
||||
fc1WScale = 6.4
|
||||
fc1BValue = 1
|
||||
fc2WScale = 3.2
|
||||
fc2BValue = 1
|
||||
fc3WScale = 3.2
|
||||
fc3BValue = 0
|
||||
]
|
||||
|
||||
DNN=[
|
||||
# conv1
|
||||
kW1 = 11
|
||||
kH1 = 11
|
||||
cMap1 = 64
|
||||
hStride1 = 4
|
||||
vStride1 = 4
|
||||
# weight[cMap1, kW1 * kH1 * ImageC]
|
||||
conv1 = ConvReLULayer(features, cMap1, 363, kW1, kH1, hStride1, vStride1, conv1WScale, conv1BValue)
|
||||
|
||||
# pool1
|
||||
pool1W = 3
|
||||
pool1H = 3
|
||||
pool1hStride = 2
|
||||
pool1vStride = 2
|
||||
pool1 = MaxPooling(conv1, pool1W, pool1H, pool1hStride, pool1vStride, imageLayout = "cudnn")
|
||||
|
||||
# conv2
|
||||
kW2 = 5
|
||||
kH2 = 5
|
||||
cMap2 = 192
|
||||
hStride2 = 1
|
||||
vStride2 = 1
|
||||
# weight[cMap2, kW2 * kH2 * cMap1]
|
||||
conv2 = ConvReLULayer(pool1, cMap2, 1600, kW2, kH2, hStride2, vStride2, conv2WScale, conv2BValue)
|
||||
|
||||
# pool2
|
||||
pool2W = 3
|
||||
pool2H = 3
|
||||
pool2hStride = 2
|
||||
pool2vStride = 2
|
||||
pool2 = MaxPooling(conv2, pool2W, pool2H, pool2hStride, pool2vStride, imageLayout = "cudnn")
|
||||
|
||||
# conv3
|
||||
kW3 = 3
|
||||
kH3 = 3
|
||||
cMap3 = 384
|
||||
hStride3 = 1
|
||||
vStride3 = 1
|
||||
# weight[cMap3, kW3 * kH3 * cMap2]
|
||||
conv3 = ConvReLULayer(pool2, cMap3, 1728, kW3, kH3, hStride3, vStride3, conv3WScale, conv3BValue)
|
||||
|
||||
# conv4
|
||||
kW4 = 3
|
||||
kH4 = 3
|
||||
cMap4 = 256
|
||||
hStride4 = 1
|
||||
vStride4 = 1
|
||||
# weight[cMap4, kW4 * kH4 * cMap3]
|
||||
conv4 = ConvReLULayer(conv3, cMap4, 3456, kW4, kH4, hStride4, vStride4, conv4WScale, conv4BValue)
|
||||
|
||||
# conv5
|
||||
kW5 = 3
|
||||
kH5 = 3
|
||||
cMap5 = 256
|
||||
hStride5 = 1
|
||||
vStride5 = 1
|
||||
# weight[cMap5, kW5 * kH5 * cMap4]
|
||||
conv5 = ConvReLULayer(conv4, cMap5, 2304, kW5, kH5, hStride5, vStride5, conv5WScale, conv5BValue)
|
||||
|
||||
roi = ROIPooling(rois, conv5.y, 6, 6)
|
||||
rshp = Reshape(roi, 9216, imageWidth=6, imageHeight=6, imageChannels=256, imageLayout="CHW")
|
||||
|
||||
hiddenDim = 4096
|
||||
h1 = DNNImageReLULayer(6, 6, 256, hiddenDim, rshp, fc1WScale, fc1BValue)
|
||||
h1_d = Dropout(h1)
|
||||
h2 = DNNReLULayer(hiddenDim, hiddenDim, h1_d, fc2WScale, fc2BValue)
|
||||
h2_d = Dropout(h2)
|
||||
ol = DNNLastLayer(hiddenDim, 21, h2_d, fc3WScale, fc3BValue)
|
||||
|
||||
rshpROI = Reshape(roiLabels, 21, imageWidth=21, imageHeight=1, imagechannels=1, imageLayout="CHW")
|
||||
rshpLabels = ReconcileDynamicAxis(rshpROI, rshp)
|
||||
|
||||
CE = CrossEntropyWithSoftmax(rshpLabels, ol, tag = Criteria)
|
||||
Err = ErrorPrediction(rshpLabels, ol, tag = Eval)
|
||||
OutputNodes = ol
|
||||
]
|
|
@ -1,110 +0,0 @@
|
|||
load=ndlMacros
|
||||
run=DNN
|
||||
|
||||
ndlMacros = [
|
||||
ImageW = 224
|
||||
ImageH = 224
|
||||
ImageC = 3
|
||||
LabelDim = 100
|
||||
# roiDim = 40
|
||||
|
||||
features = ImageInput(ImageW, ImageH, ImageC, tag = feature, imageLayout = "cudnn")
|
||||
labels = Input(LabelDim, tag = label)
|
||||
# rois = Input(roiDim, tag = feature)
|
||||
|
||||
conv1WScale = 0.95
|
||||
conv1BValue = 0
|
||||
conv2WScale = 2
|
||||
conv2BValue = 1
|
||||
conv3WScale = 2.07
|
||||
conv3BValue = 0
|
||||
conv4WScale = 2.9
|
||||
conv4BValue = 1
|
||||
conv5WScale = 2.4
|
||||
conv5BValue = 1
|
||||
fc1WScale = 6.4
|
||||
fc1BValue = 1
|
||||
fc2WScale = 3.2
|
||||
fc2BValue = 1
|
||||
fc3WScale = 3.2
|
||||
fc3BValue = 1
|
||||
]
|
||||
|
||||
DNN=[
|
||||
# conv1
|
||||
kW1 = 11
|
||||
kH1 = 11
|
||||
cMap1 = 64
|
||||
hStride1 = 4
|
||||
vStride1 = 4
|
||||
# weight[cMap1, kW1 * kH1 * ImageC]
|
||||
conv1 = ConvReLULayer(features, cMap1, 363, kW1, kH1, hStride1, vStride1, conv1WScale, conv1BValue)
|
||||
|
||||
# pool1
|
||||
pool1W = 3
|
||||
pool1H = 3
|
||||
pool1hStride = 2
|
||||
pool1vStride = 2
|
||||
pool1 = MaxPooling(conv1, pool1W, pool1H, pool1hStride, pool1vStride, imageLayout = "cudnn")
|
||||
|
||||
# conv2
|
||||
kW2 = 5
|
||||
kH2 = 5
|
||||
cMap2 = 192
|
||||
hStride2 = 1
|
||||
vStride2 = 1
|
||||
# weight[cMap2, kW2 * kH2 * cMap1]
|
||||
conv2 = ConvReLULayer(pool1, cMap2, 1600, kW2, kH2, hStride2, vStride2, conv2WScale, conv2BValue)
|
||||
|
||||
# pool2
|
||||
pool2W = 3
|
||||
pool2H = 3
|
||||
pool2hStride = 2
|
||||
pool2vStride = 2
|
||||
pool2 = MaxPooling(conv2, pool2W, pool2H, pool2hStride, pool2vStride, imageLayout = "cudnn")
|
||||
|
||||
# conv3
|
||||
kW3 = 3
|
||||
kH3 = 3
|
||||
cMap3 = 384
|
||||
hStride3 = 1
|
||||
vStride3 = 1
|
||||
# weight[cMap3, kW3 * kH3 * cMap2]
|
||||
conv3 = ConvReLULayer(pool2, cMap3, 1728, kW3, kH3, hStride3, vStride3, conv3WScale, conv3BValue)
|
||||
|
||||
# conv4
|
||||
kW4 = 3
|
||||
kH4 = 3
|
||||
cMap4 = 256
|
||||
hStride4 = 1
|
||||
vStride4 = 1
|
||||
# weight[cMap4, kW4 * kH4 * cMap3]
|
||||
conv4 = ConvReLULayer(conv3, cMap4, 3456, kW4, kH4, hStride4, vStride4, conv4WScale, conv4BValue)
|
||||
|
||||
# conv5
|
||||
kW5 = 3
|
||||
kH5 = 3
|
||||
cMap5 = 256
|
||||
hStride5 = 1
|
||||
vStride5 = 1
|
||||
# weight[cMap5, kW5 * kH5 * cMap4]
|
||||
conv5 = ConvReLULayer(conv4, cMap5, 2304, kW5, kH5, hStride5, vStride5, conv5WScale, conv5BValue)
|
||||
|
||||
# pool3
|
||||
pool3W = 3
|
||||
pool3H = 3
|
||||
pool3hStride = 2
|
||||
pool3vStride = 2
|
||||
pool3 = MaxPooling(conv5, pool3W, pool3H, pool3hStride, pool3vStride, imageLayout = "cudnn")
|
||||
|
||||
hiddenDim = 4096
|
||||
h1 = DNNImageReLULayer(6, 6, 256, hiddenDim, pool3, fc1WScale, fc1BValue)
|
||||
h1_d = Dropout(h1)
|
||||
h2 = DNNReLULayer(hiddenDim, hiddenDim, h1_d, fc2WScale, fc2BValue)
|
||||
h2_d = Dropout(h2)
|
||||
ol = DNNLastLayer(hiddenDim, labelDim, h2_d, fc3WScale, fc3BValue)
|
||||
|
||||
CE = CrossEntropyWithSoftmax(labels, ol, tag = Criteria)
|
||||
Err = ErrorPrediction(labels, ol, tag = Eval)
|
||||
OutputNodes = ol
|
||||
]
|
|
@ -1,9 +0,0 @@
|
|||
m1 = LoadModel("$curModel$", format="cntk")
|
||||
SetDefaultModel(m1)
|
||||
|
||||
newFeatures = ImageInput($newHeight$, $newWidth$, 3, tag=feature, imageLayout="cudnn")
|
||||
SetInput(conv1.c, 1, newFeatures)
|
||||
DeleteNode(features)
|
||||
Rename(newFeatures, features)
|
||||
|
||||
SaveModel(m1, "$newModel$", format="cntk")
|
|
@ -1,18 +0,0 @@
|
|||
m1 = LoadModel("$curModel$", format="cntk")
|
||||
SetDefaultModel(m1)
|
||||
|
||||
roiDim = $TestROIDim$
|
||||
roiLabelDim = $TestROILabelDim$
|
||||
|
||||
# replace the input rois
|
||||
testrois = Input(roiDim, tag="feature")
|
||||
SetInput(roi, 0, testrois)
|
||||
DeleteNode(rois)
|
||||
Rename(testrois, rois)
|
||||
|
||||
# replace the labels--could also delete this node
|
||||
testRoiLabels = Input(roiLabelDim, tag="label")
|
||||
SetInput(rshpROI, 0, testRoiLabels)
|
||||
DeleteNode(roiLabels)
|
||||
|
||||
SaveModel(m1, "$newModel$", format="cntk")
|
|
@ -1,58 +0,0 @@
|
|||
m1 = LoadModel("$curModel$", format="cntk")
|
||||
SetDefaultModel(m1)
|
||||
|
||||
SetProperty(pool2, "NeedsGradient", "false")
|
||||
SetProperty(roi, "NeedsGradient", "false")
|
||||
|
||||
SetProperty(conv2.W, "NeedsGradient", "false")
|
||||
SetProperty(conv2.b, "NeedsGradient", "false")
|
||||
SetProperty(conv2.c, "NeedsGradient", "false")
|
||||
SetProperty(conv2.z, "NeedsGradient", "false")
|
||||
SetProperty(conv2.y, "NeedsGradient", "false")
|
||||
|
||||
SetProperty(conv3.W, "NeedsGradient", "false")
|
||||
SetProperty(conv3.b, "NeedsGradient", "false")
|
||||
SetProperty(conv3.c, "NeedsGradient", "false")
|
||||
SetProperty(conv3.z, "NeedsGradient", "false")
|
||||
SetProperty(conv3.y, "NeedsGradient", "false")
|
||||
|
||||
SetProperty(conv4.W, "NeedsGradient", "false")
|
||||
SetProperty(conv4.b, "NeedsGradient", "false")
|
||||
SetProperty(conv4.c, "NeedsGradient", "false")
|
||||
SetProperty(conv4.z, "NeedsGradient", "false")
|
||||
SetProperty(conv4.y, "NeedsGradient", "false")
|
||||
|
||||
SetProperty(conv5.W, "NeedsGradient", "false")
|
||||
SetProperty(conv5.b, "NeedsGradient", "false")
|
||||
SetProperty(conv5.c, "NeedsGradient", "false")
|
||||
SetProperty(conv5.z, "NeedsGradient", "false")
|
||||
SetProperty(conv5.y, "NeedsGradient", "false")
|
||||
|
||||
SetProperty(pool2, "learningRateMultiplier", "0")
|
||||
SetProperty(roi, "learningRateMultiplier", "0")
|
||||
|
||||
SetProperty(conv2.W, "learningRateMultiplier", "0")
|
||||
SetProperty(conv2.b, "learningRateMultiplier", "0")
|
||||
SetProperty(conv2.c, "learningRateMultiplier", "0")
|
||||
SetProperty(conv2.z, "learningRateMultiplier", "0")
|
||||
SetProperty(conv2.y, "learningRateMultiplier", "0")
|
||||
|
||||
SetProperty(conv3.W, "learningRateMultiplier", "0")
|
||||
SetProperty(conv3.b, "learningRateMultiplier", "0")
|
||||
SetProperty(conv3.c, "learningRateMultiplier", "0")
|
||||
SetProperty(conv3.z, "learningRateMultiplier", "0")
|
||||
SetProperty(conv3.y, "learningRateMultiplier", "0")
|
||||
|
||||
SetProperty(conv4.W, "learningRateMultiplier", "0")
|
||||
SetProperty(conv4.b, "learningRateMultiplier", "0")
|
||||
SetProperty(conv4.c, "learningRateMultiplier", "0")
|
||||
SetProperty(conv4.z, "learningRateMultiplier", "0")
|
||||
SetProperty(conv4.y, "learningRateMultiplier", "0")
|
||||
|
||||
SetProperty(conv5.W, "learningRateMultiplier", "0")
|
||||
SetProperty(conv5.b, "learningRateMultiplier", "0")
|
||||
SetProperty(conv5.c, "learningRateMultiplier", "0")
|
||||
SetProperty(conv5.z, "learningRateMultiplier", "0")
|
||||
SetProperty(conv5.y, "learningRateMultiplier", "0")
|
||||
|
||||
SaveModel(m1, "$newModel$", format="cntk")
|
|
@ -1,34 +0,0 @@
|
|||
ConvReLULayer(inp, outMap, inWCount, kW, kH, hStride, vStride, wScale, bValue)
|
||||
[
|
||||
W = Parameter(outMap, inWCount, init = Gaussian, initValueScale = wScale)
|
||||
b = ImageParameter(1, 1, outMap, init = fixedValue, value = bValue, imageLayout = "cudnn")
|
||||
c = Convolution(W, inp, kW, kH, outMap, hStride, vStride, zeroPadding = true, imageLayout = "cudnn")
|
||||
z = Plus(c, b);
|
||||
y = RectifiedLinear(z);
|
||||
]
|
||||
|
||||
DNNReLULayer(inDim, outDim, x, wScale, bValue)
|
||||
[
|
||||
W = Parameter(outDim, inDim, init = Gaussian, initValueScale = wScale)
|
||||
b = Parameter(outDim, init = fixedValue, value = bValue)
|
||||
t = Times(W, x)
|
||||
z = Plus(t, b)
|
||||
y = RectifiedLinear(z)
|
||||
]
|
||||
|
||||
DNNImageReLULayer(inW, inH, inC, outDim, x, wScale, bValue)
|
||||
{
|
||||
W = ImageParameter(outDim, inW, inH, inC, init = "gaussian", initValueScale = wScale, imageLayout = "cudnn")
|
||||
b = Parameter(outDim, init = fixedValue, value = bValue)
|
||||
t = Times(W, x)
|
||||
z = Plus(t, b)
|
||||
y = RectifiedLinear(z)
|
||||
}
|
||||
|
||||
DNNLastLayer(hiddenDim, labelDim, x, wScale, bValue)
|
||||
[
|
||||
W = Parameter(labelDim, hiddenDim, init = Gaussian, initValueScale = wScale)
|
||||
b = Parameter(labelDim, init = fixedValue, value = bValue)
|
||||
t = Times(W, x)
|
||||
z = Plus(t, b)
|
||||
]
|
|
@ -1,212 +0,0 @@
|
|||
RootDir = "."
|
||||
ConfigDir = "$RootDir$"
|
||||
DataDir = "$ConfigDir$/data/"
|
||||
OutputDir = "D:"
|
||||
ModelDir = "D:"
|
||||
|
||||
ndlMacros="$ConfigDir$/Macros.ndl"
|
||||
|
||||
precision="float"
|
||||
deviceId="Auto"
|
||||
parallelTrain="false"
|
||||
command=FixForTest:Write
|
||||
|
||||
#stderr="$OutputDir$/AlexNet"
|
||||
traceLevel=1
|
||||
numMBsToShowResult=50
|
||||
|
||||
FinalModel = "AlexNet.rcnn.just_resize.allim.pad"
|
||||
|
||||
#### dimension variables; used here and in MEL files. ####
|
||||
|
||||
# 200 rois per image * 4 points per ROI
|
||||
TestROIDim = 800
|
||||
# 200 rois per image * 21 object classes
|
||||
TestROILabelDim = 4200
|
||||
|
||||
# 64 rois per image for training
|
||||
TrainROIDim = 256
|
||||
TrainROILabelDim = 1344
|
||||
LabelDim = 21
|
||||
|
||||
#### end dimension variables ####
|
||||
|
||||
AddROILayer=[
|
||||
action="edit"
|
||||
CurModel="$ConfigDir$/AlexNet.89"
|
||||
NewModel="$ModelDir$/$FinalModel$.0"
|
||||
editPath="$ConfigDir$/AddROILayer.mel"
|
||||
]
|
||||
|
||||
JustLast=[
|
||||
action="edit"
|
||||
CurModel="$ModelDir$/$FinalModel$"
|
||||
NewModel="$ModelDir$/$FinalModel$"
|
||||
editPath="$ConfigDir$/JustLast.mel"
|
||||
]
|
||||
|
||||
ChangeInputSize=[
|
||||
action="edit"
|
||||
NewHeight = 500
|
||||
NewWidth = 500
|
||||
CurModel="$ModelDir$/$FinalModel$.0"
|
||||
NewModel="$ModelDir$/$FinalModel$.0"
|
||||
editPath="$ConfigDir$/ChangeInputSize.mel"
|
||||
]
|
||||
|
||||
FixForTest=[
|
||||
action="edit"
|
||||
CurModel="$ModelDir$/$FinalModel$.0"
|
||||
NewModel="$ModelDir$/$FinalModel$.test"
|
||||
editPath="$ConfigDir$/FixForTest.mel"
|
||||
]
|
||||
|
||||
Train=[
|
||||
action="train"
|
||||
|
||||
modelPath="$ModelDir$/$FinalModel$"
|
||||
NDLNetworkBuilder=[
|
||||
networkDescription="$ConfigDir$/AlexNet.ndl"
|
||||
]
|
||||
|
||||
SGD=[
|
||||
epochSize=0
|
||||
minibatchSize=2
|
||||
learningRatesPerMB=0.001*5:0.0001
|
||||
momentumPerMB=0.9
|
||||
maxEpochs=15
|
||||
gradUpdateType=None
|
||||
L2RegWeight=0.0005
|
||||
dropoutRate=0.5
|
||||
|
||||
ParallelTrain=[
|
||||
parallelizationMethod="DataParallelSGD"
|
||||
distributedMBReading="true"
|
||||
parallelizationStartEpoch=1
|
||||
DataParallelSGD=[
|
||||
gradientBits=32
|
||||
]
|
||||
]
|
||||
|
||||
numMBsToShowResult=50
|
||||
|
||||
]
|
||||
reader=[
|
||||
randomize = false
|
||||
verbosity = 2
|
||||
deserializers = (
|
||||
[
|
||||
type = "CNTKTextFormatDeserializer"
|
||||
module = "CNTKTextFormatReader"
|
||||
file = "$DataDir$/tv2012pad.rois.txt"
|
||||
input = [
|
||||
rois = [
|
||||
dim = $TrainROIDim$
|
||||
format = "dense"
|
||||
]
|
||||
]
|
||||
]:[
|
||||
type = "CNTKTextFormatDeserializer"
|
||||
module = "CNTKTextFormatReader"
|
||||
file = "$DataDir$/tv2012pad.roilabels.txt"
|
||||
input = [
|
||||
roiLabels = [
|
||||
dim = $TrainROILabelDim$
|
||||
format = "dense"
|
||||
]
|
||||
]
|
||||
]:[
|
||||
type = "ImageDeserializer"
|
||||
module = "ImageReader"
|
||||
file="$DataDir$/tv2012pad.txt"
|
||||
input = [
|
||||
features = [
|
||||
transforms = (
|
||||
[
|
||||
type = "Pad"
|
||||
width = 500
|
||||
height = 500
|
||||
channels = 3
|
||||
value = 114
|
||||
]:[
|
||||
type = "Mean"
|
||||
# Stores mean values for each pixel in OpenCV matrix XML format.
|
||||
meanFile = "$ConfigDir$/ImageNet500_mean.xml"
|
||||
]:[
|
||||
# Changes the image layout from HWC to CHW
|
||||
type = "Transpose"
|
||||
]
|
||||
)
|
||||
]
|
||||
ignored=[
|
||||
labelDim=1000
|
||||
]
|
||||
]
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
|
||||
Write=[
|
||||
action="write"
|
||||
modelPath="$ModelDir$/$FinalModel$.test"
|
||||
# Set minibatch size for testing.
|
||||
minibatchSize=8
|
||||
outputPath="$OutputDir$/justlast_sanity-test200-withcasts"
|
||||
reader=[
|
||||
randomize = false
|
||||
verbosity = 2
|
||||
deserializers = (
|
||||
[
|
||||
type = "CNTKTextFormatDeserializer"
|
||||
module = "CNTKTextFormatReader"
|
||||
file = "$DataDir$/test2007pad_all.rois.txt"
|
||||
input = [
|
||||
rois = [
|
||||
dim = $TestROIDim$
|
||||
format = "dense"
|
||||
]
|
||||
]
|
||||
]:[
|
||||
type = "CNTKTextFormatDeserializer"
|
||||
module = "CNTKTextFormatReader"
|
||||
file = "$DataDir$/test2007pad_all.roilabels.txt"
|
||||
input = [
|
||||
roiLabels = [
|
||||
dim = $TestROILabelDim$
|
||||
format = "dense"
|
||||
]
|
||||
]
|
||||
]:[
|
||||
type = "ImageDeserializer"
|
||||
module = "ImageReader"
|
||||
file="$DataDir$/test2007pad_all.txt"
|
||||
input = [
|
||||
features = [
|
||||
transforms = (
|
||||
[
|
||||
type = "Pad"
|
||||
height = 500
|
||||
width = 500
|
||||
channels = 3
|
||||
value = 114
|
||||
]:[
|
||||
type = "Mean"
|
||||
# Stores mean values for each pixel in OpenCV matrix XML format.
|
||||
meanFile = "$ConfigDir$/ImageNet500_mean.xml"
|
||||
]:[
|
||||
# Changes the image layout from HWC to CHW
|
||||
type = "Transpose"
|
||||
]
|
||||
)
|
||||
]
|
||||
ignored=[
|
||||
labelDim=1000
|
||||
]
|
||||
]
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
#outputNodeNames = (features)
|
||||
]
|
Загрузка…
Ссылка в новой задаче