深度学习 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,269评论 19 139
  • 1.创建文件夹 !/bin/sh mkdir -m 777 "%%1" 2.创建文件 !/bin/sh touch...
    BigJeffWang阅读 10,267评论 3 53
  • “回家了吧?” “对啊,是不是想我了?” “今晚出来吗?陪我聊会。” “好。” 即使只是通过冰冷的手机屏幕与阿思聊...
    BelieveAi阅读 405评论 0 4
  • 一颗流星, 在夜空中奔闯。 拼尽全力, 向黑暗碰撞。 黑夜害怕流星心中的光芒, 忙把它的身躯隐藏。 却阻止不了, ...
    半月仙河北廊坊阅读 419评论 3 7