[译]英特尔®MKL-DNN:第2部分–示例代码构建和演练
By robot-v1.0
本文链接 https://www.kyfws.com/ai/intel-mkl-dnn-part-sample-code-build-and-walkthr-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 13 分钟阅读 - 6284 个词 阅读量 0英特尔®MKL-DNN:第2部分–示例代码构建和演练(译文)
原文地址:https://www.codeproject.com/Articles/1182897/Intel-MKL-DNN-Part-Sample-Code-Build-and-Walkthr
原文作者:Intel Corporation
译文由本站 robot-v1.0 翻译
前言
*In Part 2 we will explore how to configure an integrated development environment (IDE) to build the C++ code example, and provide a code walkthrough based on the AlexNet deep learning topology. *
在第2部分中,我们将探索如何配置集成开发环境(IDE)来构建C ++代码示例,并提供基于AlexNet深度学习拓扑的代码演练.
介绍(Introduction)
在(In) 第1部分(Part 1) 我们推出了用于深度神经网络的英特尔®数学内核库(英特尔®MKL-DNN),这是一种用于深度学习应用程序的开源性能库.提供了有关如何在具有支持Intel®Advanced Vector Extensions 2(Intel®AVX2)的Intel处理器并运行Ubuntu 操作系统的计算机上安装库组件的详细步骤.第1部分还介绍了有关如何从命令行构建C和C ++代码示例的详细信息.(we introduced Intel® Math Kernel Library for Deep Neural Networks (Intel® MKL-DNN), an open source performance library for deep learning applications. Detailed steps were provided on how to install the library components on a computer with an Intel processor supporting Intel® Advanced Vector Extensions 2 (Intel® AVX2) and running the Ubuntu operating system. Details on how to build the C and C++ code examples from the command line were also covered in Part 1.)
在第2部分中,我们将探索如何配置集成开发环境(IDE)来构建C ++代码示例,并提供基于AlexNet 深度学习拓扑的代码演练.在本教程中,我们将使用(In Part 2 we will explore how to configure an integrated development environment (IDE) to build the C++ code example, and provide a code walkthrough based on the AlexNet deep learning topology. In this tutorial we’ll be working with the) 日食霓虹灯(Eclipse Neon) * IDE与(** IDE with the*) C/C ++开发工具(CDT)(C/C++ Development Tools (CDT)) . (如果您的系统尚未安装Eclipse *,则可以按照(*. (If your system does not already have Eclipse* installed you can follow the directions on the*) Ubuntu手册(Ubuntu Handbook) 网站,为C/C ++开发人员指定Oracle Java * 8和Eclipse IDE.)(*site, specifying the Oracle Java* 8 and Eclipse IDE for C/C++ Developers options.)*)
在Eclipse IDE中构建C ++示例(Building the C++ Example in Eclipse IDE)
本节介绍如何在Eclipse中创建新项目以及如何导入Intel MKL-DNN C ++示例代码.(This section describes how to create a new project in Eclipse and import the Intel MKL-DNN C++ example code.)
在Eclipse中创建一个新项目:(Create a new project in Eclipse:)
- 启动Eclipse.(Start Eclipse.)
- 请点击(Click)新(New)在屏幕的左上角.(in the upper left-hand corner of screen.)
- 在里面(In the)**选择一个向导(Select a wizard)**屏幕,选择(screen, select)C ++专案(C++ Project)然后点击(and then click)下一个(Next)(图1).((Figure 1).)
图1.在Eclipse中创建一个新的C ++项目.(Figure 1. Create a new C++ project in Eclipse.)
-
输入(Enter)simple_net(simple_net)项目名称.对于项目类型,选择(for the project name. For the project type select)可执行的空白项目(Executable, Empty Project).对于工具链,请选择(. For toolchain select)Linux GCC(Linux GCC).请点击(. Click)下一个(Next).(.)
-
在里面(In the)**选择配置(Select Configurations)**屏幕上,单击(screen, click)高级设置(Advanced Settings).(.) 为项目启用C ++ 11:(Enable C++11 for the project:)
-
在里面(In the)物产(Properties)屏幕上,展开(screen, expand the)C/C ++构建(C/C++ Build)菜单树中的选项,然后选择(option in the menu tree and then select)设定值(Settings).(.)
-
在里面(In the)**工具设定(Tool Settings)**标签,选择(tab, select)GCC C ++编译器(GCC C++ Compiler), 接着(, and then)杂(Miscellaneous).(.)
-
在里面(In the)**其他标志(Other flags)**框添加-(box add -)std =c ++ 11(std=c++11)到现有字符串的末尾,以空格分隔(图2).(to the end of existing string separated by a space (Figure 2).)
图2为项目启用C ++ 11(2之1).(Figure 2 Enable C++11 for the project (1 of 2).)
- 在里面(In the)**物产(Properties)**屏幕上,展开(screen, expand the)C/C ++常规(C/C++ General)然后选择(and then select)预处理器包含路径,宏等(Preprocessor Include Paths, Macros etc.)
- 选择(Select the)提供者(Providers)标签,然后选择您正在使用的编译器(例如,(tab and then select the compiler you are using (for example,)CDT GCC内置编译器设置(CDT GCC Built-in Compiler Settings)).().)
- 找到名为(Locate the field named)**获取编译器规格的命令:(Command to get compiler specs:)**并添加(and add)
-std=c++11
.完成后,该命令应类似于以下内容:(. The command should look similar to this when finished:) " $ {COMMAND} $ {FLAGS} -E -P -v -dD" $ {INPUTS}" -std =c ++ 11".("${COMMAND} ${FLAGS} -E -P -v -dD “${INPUTS}” -std=c++11".) - 请点击(Click)应用(Apply)接着(and then)好(OK)(图3).((Figure 3).)
图3为项目启用C ++ 11(2之2).(Figure 3 Enable C++11 for the project (2 of 2).)将库添加到链接器设置:(Add library to linker settings:)
- 在里面(In the)**物产(Properties)**屏幕上,展开(screen, expand the)C/C ++构建(C/C++ Build)菜单树中的选项,然后选择(option in the menu tree and then select)设定值(Settings).(.)
- 在里面(In the)**工具设定(Tool Settings)**标签,选择(tab, select)GCC C ++链接器(GCC C++ Linker), 接着(, and then)图书馆(Libraries).(.)
- 在下面(Under the)**图书馆(l)(Libraries (l))**部分点击(section click)加(Add).(.)
- 输入(Enter)麦克尔登(mkldnn)然后点击(and then click)好(OK)(图4).((Figure 4).)
图4将库添加到链接器设置.(Figure 4 Add library to linker settings.)完成创建项目:(Finish creating the project:)
-
请点击(Click)好(OK)在底部(at the bottom of the)**物产(Properties)**屏幕.(screen.)
-
请点击(Click)完(Finish)在底部(at the bottom of the)**C ++专案(C++ Project)**屏幕.(screen.) 添加C ++源文件(请注意:此时,(Add the C++ source file (note: at this point the)**simple_net(simple_net)**项目应出现在Project Explorer中):(project should appear in Project Explorer):)
-
在项目资源管理器中右键单击项目名称,然后选择(Right-click the project name in Project Explorer and select)新(New),(,)源文件夹(Source Folder).输入(. Enter)src(src)为文件夹名称,然后单击(for the folder name and then click)完(Finish).(.)
-
右键点击(Right-click the)**src(src)**项目浏览器中的文件夹,然后选择(folder in Project Explorer and select)进口…(Import…)
-
在里面(In the)**进口(Import)**屏幕上,展开(screen, expand the)一般(General)文件夹,然后突出显示(folder and then highlight)文件系统(File System).请点击(. Click)下一个(Next).(.)
-
在里面(In the)**文件系统(File System)**屏幕上,单击(screen, click the)浏览(Browse)旁边的按钮(button next to the)从目录(From directory)领域.导航到包含英特尔MKL-DNN示例文件的位置,在我们的例子中是(field. Navigate to the location containing the Intel MKL-DNN example files, which in our case is)/mkl-dnn/examples(/mkl-dnn/examples).请点击(. Click)好(OK)在屏幕底部.(at the bottom of the screen.)
-
回到(Back in the)**文件系统(File System)**屏幕上,检查(screen, check the)simple_net.cpp(simple_net.cpp)框,然后单击(box and then click)完(Finish).(.) 生成Simple_Net项目:(Build the Simple_Net project:)
-
右键单击项目名称(Right-click on the project name)simple_net(simple_net)在(in)项目浏览器(Project Explorer).(.)
-
点击(Click on)建立项目(Build Project)并确认没有遇到错误.(and verify no errors are encountered.)
Simple_Net代码示例(Simple_Net Code Example)
尽管它不是一个功能全面的深度学习框架,但Simple_Net提供了如何构建神经网络拓扑块的基础,该神经网络拓扑块由卷积,整流线性单元(ReLU),局部响应规范化(LRN)和池化全部包含在可执行项目中.英特尔MKL-DNN C ++ API的简要分步描述在(Although it’s not a fully functional deep learning framework, Simple_Net provides the basics of how to build a neural network topology block that consists of convolution, rectified linear unit (ReLU), local response normalization (LRN), and pooling, all in an executable project. A brief step-by-step description of the Intel MKL-DNN C++ API is presented in the) 文件资料(documentation) ;但是,Simple_Net代码示例基于AlexNet拓扑提供了更完整的演练.因此,我们将首先简要介绍AlexNet架构.(; however, the Simple_Net code example provides a more complete walkthrough based on the AlexNet topology. Hence, we will begin by presenting a brief overview of the AlexNet architecture.)
AlexNet架构(AlexNet Architecture)
如论文所述(As described in the paper) 深度卷积神经网络的ImageNet分类(ImageNet Classification with Deep Convolutional Neural Networks) ,AlexNet体系结构包含一个输入图像(L0)和八个学习层(L1至L8)—五层卷积和三层完全连接.图5以图形方式描绘了该拓扑.(, the AlexNet architecture contains an input image (L0) and eight learned layers (L1 through L8)—five convolutional and three fully-connected. This topology is depicted graphically in Figure 5.)
图5 AlexNet拓扑(来源:(Figure 5 AlexNet topology (credit:) 麻省理工学院(MIT) ).(**).)表1提供了AlexNet体系结构的其他详细信息:(Table 1 provides additional details of the AlexNet architecture:)
|层(Layer)
|类型(Type)
|描述(Description)
L0 |
|输入图像(Input image)
|尺寸:227 x 227 x 3(在图中显示为227 x 227 x 3)(Size: 227 x 227 x 3 (shown in diagram as 227 x 227 x 3))
| |L1
|Convolution
|尺寸:55 * x 55 x 96(Size: 55 x 55 x 96*)
- 96个滤镜,尺寸11×11(96 filters, size 11 × 11)
- 大步前进4(Stride 4)
- 填充0(Padding 0) *大小=(N-F)/S +1 =(227-11)/4 +1 =55(*Size = (N - F)/S + 1 = (227 - 11)/4 + 1 = 55)
|Max-pooling
|尺寸:27 * x 27 x 96(Size: 27 x 27 x 96*)
- 96个滤镜,尺寸3×3(96 filters, size 3 × 3)
- 大步前进2(Stride 2) *尺寸=(N-F)/S +1 =(55 – 3)/2 +1 =27(*Size = (N - F)/S + 1 = (55 – 3)/2 + 1 = 27)
| |L2
|Convolution
|尺寸:27 x 27 x 256(Size: 27 x 27 x 256)
- 256个滤镜,尺寸5 x 5(256 filters, size 5 x 5)
- 大步1(Stride 1)
- 填充2(Padding 2)
|Max-pooling
|尺寸:13 * x 13 x 256(Size: 13 x 13 x 256*)
- 256个滤镜,尺寸3×3(256 filters, size 3 × 3)
- 大步前进2(Stride 2) *大小=(N-F)/S +1 =(27-3)/2 +1 =13(*Size = (N - F)/S + 1 = (27 - 3)/2 + 1 = 13)
| |L3
|Convolution
|尺寸:13 x 13 x 384(Size: 13 x 13 x 384)
- 384个滤镜,尺寸3×3(384 filters, size 3 × 3)
- 大步1(Stride 1)
- 填充1(Padding 1) | |L4
|Convolution
|尺寸:13 x 13 x 384(Size: 13 x 13 x 384)
- 384个滤镜,尺寸3×3(384 filters, size 3 × 3)
- 大步1(Stride 1)
- 填充1(Padding 1) | |L5
|Convolution
|尺寸:13 x 13 x 256(Size: 13 x 13 x 256)
- 256个滤镜,尺寸3×3(256 filters, size 3 × 3)
- 大步1(Stride 1)
- 填充1(Padding 1)
|Max-pooling
|尺寸:6 * x 6 x 256(Size: 6 x 6 x 256*)
- 256个滤镜,尺寸3×3(256 filters, size 3 × 3)
- 大步前进2(Stride 2) *大小=(N-F)/S +1 =(13-3)/2 +1 =6(*Size = (N - F)/S + 1 = (13 - 3)/2 + 1 = 6)
| |L6
|完全连接(Fully Connected)
|4096个神经元(4096 neurons)
| |L7
|完全连接(Fully Connected)
|4096个神经元(4096 neurons)
| |L8
|完全连接(Fully Connected)
|1000个神经元(1000 neurons)
|
表1. AlexNet层描述.(Table 1. AlexNet layer descriptions.)卷积神经网络和AlexNet拓扑的详细描述超出了本教程的范围,但是如果需要更多信息,读者可能会发现以下链接很有用.(A detailed description of convolutional neural networks and the AlexNet topology is beyond the scope of this tutorial, but the reader may find the following links useful if more information is required.)
- 维基百科-卷积神经网络(Wikipedia - Convolutional Neural Networks)
- 卷积神经网络简介(Introduction to Convolutional Neural Nets)
- 用于视觉识别的卷积神经网络(Convolutional Neural Networks for Visual Recognition)
- 卷积神经网络的直观解释(An Intuitive Explanation of Convolutional Neural Networks)
Simple_Net代码演练(Simple_Net Code Walkthrough)
下面显示的源代码与存储库中包含的Simple_Net示例基本相同,不同之处在于,已对其进行重构以使用完全合格的Intel MKL-DNN类型来增强可读性.此代码实现拓扑的第一层(L1).(The source code presented below is essentially the same as the Simple_Net example contained in the repository, except it has been refactored to use the fully qualified Intel MKL-DNN types to enhance readability. This code implements the first layer (L1) of the topology.)
- 为库头文件添加include指令:(Add include directive for the library header file:)
- 初始化CPU引擎为索引0:(Initialize the CPU engine as index 0:)
- 分配数据并创建张量结构:(Allocate data and create tensor structures:)
- 创建用于用户数据的内存:(Create memory for user data:)
- 使用通配符为卷积数据创建内存描述符(Create memory descriptors for convolution data using the wildcard)**任何(any)**用于卷积数据格式(这使卷积原语可以选择最适合其输入参数(内核大小,步幅,填充等)的数据格式):(for the convolution data format (this enables the convolution primitive to choose the data format that is most suitable for its input parameters—kernel sizes, strides, padding, and so on):)
- 通过指定算法,传播类型,输入形状,权重,偏差,输出以及卷积步幅,填充和填充类型来创建卷积描述符:(Create a convolution descriptor by specifying the algorithm, propagation kind, shapes of input, weights, bias, output, and convolution strides, padding, and padding kind:)
- 创建卷积图元的描述符.创建后,此描述符具有特定的格式,而不是卷积描述符中指定的任何通配符格式:(Create a descriptor of the convolution primitive. Once created, this descriptor has specific formats instead of any wildcard formats specified in the convolution descriptor:)
- 创建一个表示网络的图元向量:(Create a vector of primitives that represents the net:)
- 如果需要,在用户和数据之间创建重新排序,并在卷积之前将其添加到网络:(Create reorders between user and data if it is needed and add it to net before convolution:)
- 创建卷积图元并将其添加到网络:(Create convolution primitive and add it to net:)
- 创建一个ReLU原语并将其添加到net:(Create a ReLU primitive and add it to net:)
- 创建一个AlexNet LRN原语:(Create an AlexNet LRN primitive:)
- 创建一个AlexNet池原语:(Create an AlexNet pooling primitive:)
- 从池化dst创建池化索引内存:(Create pooling indices memory from pooling dst:)
- 创建池原语并将其添加到net:(Create pooling primitive and add it to net:)
- 如果需要,在内部数据和用户数据之间创建重新排序,并在合并后将其添加到网络中:(Create reorder between internal and user data if it is needed and add it to net after pooling:)
- 创建一个流,提交所有原语,然后等待完成:(Create a stream, submit all the primitives, and wait for completion:)
- 上述代码包含在(The code described above is contained in the)
simple_net()
函数,在(function, which is called in)main
带有异常处理:(with exception handling:)
结论(Conclusion)
第1部分(Part 1) 本教程系列中的教程确定了一些资源,用于学习有关英特尔MKL-DNN的技术预览.还提供了有关如何安装和构建库组件的详细说明.在本文中(教程系列的第2部分),提供了有关如何配置Eclipse集成开发环境以构建C ++代码示例的信息,以及基于AlexNet深度学习拓扑的代码演练.敬请关注英特尔MKL-DNN即将量产.(of this tutorial series identified several resources for learning about the technical preview of Intel MKL-DNN. Detailed instructions on how to install and build the library components were also provided. In this paper (Part 2 of the tutorial series), information on how to configure the Eclipse integrated development environment to build the C++ code sample was provided, along with a code walkthrough based on the AlexNet deep learning topology. Stay tuned as Intel MKL-DNN approaches production release.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C C++ Ubuntu Eclipse machine-learning 新闻 翻译