深度学习 CNTK使用笔记

摘要:如今,在大数据处理的过程中,人们广泛的使用的神经网络。伴随着深度学习的这股热潮,涌现出来大量可供使用的开源软件。如,Theano,caffe,kaldi,CNTK等。CNTK是微软提供的基于C++的开源工具包。可以训练DNNs、RNNs、CNNs、LTMS、罗杰斯特回归及最大熵模型,对于在做深度学习的朋友会有帮助。

下面介绍CNTK中的几个样例的使用:

1.首先下载工具包及源码。下载地址https://cntk.codeplex.com/

2.安装。(安装过程比较麻烦,要求电脑为64位的,具体需要安装的软件见https://cntk.codeplex.com/documentation

3.安装好后,我们先跑demos试试。

(1)demos下有两个样例Simple、Speech。由于Speech中没有输入的数据(好像可以下,不过不是免费的),我就先跑了Simple样例

在运行之前,我们要更改Simple.config中的几个参数及路径的配置。下面是我的配置

RootDir=E:\cntk\cntk-code\
command=Simple_Demo:Simple_Demo_Output


# deviceId=-1 for CPU, >=0 for GPU devices
DeviceNumber=-1


#stderr=E:/log/Demo


precision=float


modelPath=E:/models/simple.dnn
deviceId=$DeviceNumber$


outputNodeNames=ScaledLogLikelihood
traceLevel=1


#######################################
#  TRAINING CONFIG (Simple, Fixed LR) #
#######################################


Simple_Demo=[
action=train


# Notation xxx:yyy*n:zzz is equivalent to xxx,
#  then yyy repeated n times, then zzz
# example: 10:20*3:5 is equivalent to 10:20:20:20:5
SimpleNetworkBuilder=[
# 2 input, 2 50-element hidden, 2 output
layerSizes=2:50*2:2
trainingCriterion=CrossEntropyWithSoftmax
evalCriterion=ErrorPrediction
layerTypes=Sigmoid
initValueScale=1.0
applyMeanVarNorm=true
uniformInit=true
needPrior=true
]


SGD=[
# epochSize=0 means epochSize is the size of
# the training set. Must be evenly divisible
# into number of data frames.
epochSize=0
minibatchSize=25
learningRatesPerMB=0.5:0.2*20:0.1
momentumPerMB=0.9
dropoutRate=0.0
maxEpochs=50
]


# Parameter values for the reader
reader=[
# reader to use
readerType=UCIFastReader
file=$RootDir$/Demos/Simple/SimpleDataTrain.txt


miniBatchMode=Partial
randomize=Auto
verbosity=1


features=[
dim=2      # two-dimensional input data
start=0    # Start with first element on line
]


labels=[
start=2      # Skip two elements
dim=1        # One label dimension
labelDim=2   # Two labels possible
labelMappingFile=$RootDir$/Demos/Simple/SimpleMapping.txt
]
]
]


#######################################
#  OUTPUT RESUTLS (Simple)            #
#######################################


Simple_Demo_Output=[
action=write




# Parameter values for the reader
reader=[
# reader to use
readerType=UCIFastReader
file=$RootDir$/Demos/Simple/SimpleDataTest.txt
features=[
dim=2
start=0
]
labels=[
start=2
dim=1
labelDim=2
labelMappingFile=$RootDir$/Demos/Simple/SimpleMapping.txt
]
]
outputPath=SimpleOutput    # Dump output as text
]

主要是修改RootDir、DeviceNumber=-1,其他的参数根据具体情况进行更改。RootDir在这里相当于一个常量,与输入的路径组成绝对路径如:$RootDir$/Demos/Simple/SimpleDataTest.txt。DeviceNumber是选择使用CPU还是GPU进行训练=-1是为CPU,>=0时为GPU。

修改完成后,在开源工具包中代开命令窗口,输入cn.exe configFile=E:/Simple.config,其中,E:/Simple.config为Simple.config文件的绝对路径,如在当前目录下输入cn.exe configFile=Simple.config即可。

完成以上步骤即可运行样例,并输出日志,对数似然率。

4.其他的样例使用与其差不多,但有些没有输入的特征数据,需要自行配置。整体思路就是使用脚本。更多方法请参考http://research.microsoft.com/pubs/226641/CNTKBook-20150415.pdf

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值