主要内容

缺陷检测

这个例子展示了如何部署一个定制的训练系列网络来检测物体的缺陷,如六边形螺母。采用迁移学习的方法对自定义网络进行训练。迁移学习通常用于深度学习应用。你可以用一个预先训练好的网络作为学习新任务的起点。用迁移学习对网络进行微调通常比用随机初始化权值从头开始训练网络更快、更容易。使用少量的训练信号,您可以快速地将学到的特征转移到新的任务中。这个例子使用了两个训练过的系列网络,trainedDefNet.mattrainedBlemDetNet.mat.

先决条件

  • Xilinx ZCU102 SoC开发工具包

  • 用于Xilinx FPGA和SoC的深度学习HDL工金宝app具箱™支持包

  • 深度学习工具箱™

  • 深度学习HDL工具箱™

负载Pretrained网络

加载定制的预训练系列网络trainedDefNet。

如果~isfile(“trainedDefNet.mat”) url ='//www.tatmou.com/金宝appsupportfiles/dlhdl/trainedDefNet.mat'; 韦伯萨夫(“trainedDefNet.mat”url);结束net1 =负载(“trainedDefNet.mat”);snet_defnet = net1.custom_alexnet
snet_defnet = SeriesNetwork with properties: Layers: [25×1 net.cnn.layer. layer] InputNames: {'data'} OutputNames: {'output'}

分析了网络。analyzeNetwork显示网络架构的交互图和包含有关网络层信息的表。

analyzeNetwork (snet_defnet)

网络负载snet_blemdetnet.

如果~isfile(“trainedBlemDetNet.mat”) url =“//www.tatmou.com/金宝appsupportfiles/dlhdl/trainedBlemDetNet.mat”; 韦伯萨夫(“trainedBlemDetNet.mat”url);结束net2 =负载(“trainedBlemDetNet.mat”);snet_blemdetnet = net2.convnet
snet_blemdetnet = SeriesNetwork with properties: Layers: [12×1 net.cnn.layer. layer] InputNames: {'imageinput'} OutputNames: {'classoutput'}

分析了网络。analyzeNetwork显示网络架构的交互图和包含有关网络层信息的表。

分析网络(snet_blemdetnet)

创建目标对象

创建一个目标对象,该对象具有目标设备的自定义名称和将目标设备连接到主机的接口。接口选项为JTAG和以太网。若要使用JTAG连接,请安装Xilinx™ 万岁™ 设计套件2020.1。

设置Xilinx Vivado工具路径。

% hdlsetuptoolpath('ToolName', 'Xilinx Vivado', 'ToolPath', 'C: Xilinx Vivado\2020.1\bin\ Vivado .bat');hT = dlhdl。目标(“Xilinx”,“界面”,“以太网”)
hT = Target with properties: Vendor: 'Xilinx' Interface: Ethernet IPAddress: '192.168.1.101' Username: 'root' Port: 22

创建工作流对象训练defnet网络

创建的对象dlhdl。工作流类。指定网络和位流名称。指定保存的预训练网络trainedDefNet随着网络。确保位流名称与您的目标数据类型和FPGA板匹配。本例中,目标FPGA板为Xilinx ZCU102 SOC板。位流使用单一数据类型。

hW = dlhdl。工作流(“网络”snet_defnet,“比特流”,“zcu102_single”,“目标”hT)
hW =带有属性的工作流:Network: [1×1 SeriesNetwork] Bitstream: 'zcu102_single' ProcessorConfig: [] Target: [1×1 dlhdl. hW = []目标]

编制trainedDefNet系列网络

的compile函数dlhdl。工作流对象。

编译
###用于深入学习FPGA原型的编译网络…#######针对FPGA比特流zcu102#单…#############该网络包括以下层:1“数据”图像输入128×128×1图像,具有“零中心”归一化(SW层)2“conv1”卷积96 11×11×1卷积,具有跨步[4]和填充[0 0 0 0 03'relu1'ReLU ReLU(硬件层)4'norm1'跨通道规格化跨通道规格化每个元素5个通道(硬件层)5'pool1'最大池3×3最大池带跨步[2]和填充[0 0 0 0 0](硬件层)6'conv2'分组卷积2组128个5×5×48卷积带跨步[1]和填充[2 2 2 2 2](硬件层)7'relu2'ReLU ReLU(硬件层)8'norm2'跨通道规格化跨通道规格化每个元素5个通道(硬件层)9'pool2'最大池3×3最大池带跨步[2]和填充[0 0 0 0](硬件层)10'conv3'卷积384 3×3×256卷积带跨步[1 1]和填充[1 1 1 1 1](硬件层)11'relu3'ReLU ReLU ReLU(硬件层)12‘conv4’分组卷积2组1923×3×192卷积,带跨步[11]和填充[11](硬件层)13‘relu4’ReLU ReLU ReLU(硬件层)14‘conv5’分组卷积2组1283×3×192卷积,带跨步[11]和填充[11](硬件层)15‘relu5’ReLU ReLU(硬件层)16'池5'最大池3×3最大池,带跨步[2]和填充[0 0 0 0 0](硬件层)17'fc6'完全连接4096完全连接层(硬件层)18'relu6'ReLU ReLU(硬件层)19'drop6'辍学50%辍学(硬件层)20'fc7'完全连接4096完全连接层(硬件层)21'relu7'ReLU ReLU ReLU(硬件层)22“drop7”Dropout 50%Dropout(硬件层)23“fc8”完全连接2完全连接层(硬件层)24“prob”Softmax Softmax(软件层)25“输出”分类输出crossentropyex,等级为“ng”和“ok”(软件层)创建了3个内存区域。跳过:数据编译段:conv1>>pool5…编译段:conv1>>pool5…完成。编译段:fc6>>fc8…编译段:fc6>>fc8…完成。跳过:prob跳过:输出创建计划…….创建计划…完成。创建状态表…….创建状态表…完成。发送(3)分配外部内存缓冲区:偏移量(名称)名称,偏移量(名称)偏移量(名称)偏移量(名称)偏移量(地址)地址,地址地址地址,地址分配了(U地址)地址,地址分配了空间,发射时间…发射日程…发射时间表…发射时间表…完成。发射状态表…完成。发射状态表…完成。发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表。发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…发射状态表…完成。发射状态表。发射状态表。发射状态表。发射状态表…完成。发射状态表…完成。发射状态表。发射状态表。发射状态表。发射状态表。发射状态表…完成。发射状态表。发射状态表…完成。发射状态表。发射状态表…完成。发射状态表。发射状态表…完成。发射0.0 MB““SchedulerDataOffset”“0x00c00000”“4.0 MB”“SystemBufferOffset”“0x01000000”“28.0 MB”“InstructionDataOffset”“0x02c00000”“4.0 MB”“ConvWeightDataOffset”“0x03000000”“12.0 MB”“FCWeightDataOffset”“0x03c00000”“84.0 MB”“EndOffset”“0x09000000”“总计:144.0 MB”“网络编译完成。”。
ans =结构体字段:[1×1 struct]注册:[1×1 struct] syncstructions: [1×1 struct]

在FPGA上编程Bitstream并下载网络权重

要在Xilinx ZCU102 SoC硬件上部署网络,请运行dlhdl。工作流对象。该函数使用compile函数的输出,利用编程文件对FPGA板进行编程。它还下载了网络权重和偏差。deploy函数开始对FPGA设备进行编程,并显示进度消息和部署网络所需的时间。

hW.deploy
###使用以太网编程FPGA Bitstream…下载目标FPGA设备配置通过以太网到SD卡…#将/tmp/hdlcoder_rd拷贝到/mnt/hdlcoder_rd。bit to /mnt/hdlcoder_rd #设置Bitstream为hdlcoder_rd/hdlcoder_system。#复制devicetree_dlhdl. bit #复制devicetree_dlhdl. bit #复制devicetree_dlhdl。dtb为/mnt/hdlcoder_rd #设置Devicetree为hdlcoder_rd/devicetree_dlhdl。dtb # Set boot for Reference Design: ' axis - stream DDR Memory Access: 3-AXIM'现在系统将重新启动以使持久更改生效。系统正在重启. . . . . .### FPGA位流编程已成功完成###加载权值到Conv处理器。### Conv权重加载。 Current time is 16-Dec-2020 16:16:31 ### Loading weights to FC Processor. ### 20% finished, current time is 16-Dec-2020 16:16:32. ### 40% finished, current time is 16-Dec-2020 16:16:32. ### 60% finished, current time is 16-Dec-2020 16:16:33. ### 80% finished, current time is 16-Dec-2020 16:16:34. ### FC Weights loaded. Current time is 16-Dec-2020 16:16:34

对一个图像运行预测

从附件中加载图像测试图像文件夹并调整图像大小以匹配网络图像输入层的尺寸。运行dlhdl。工作流对象从FPGA中检索和显示缺陷预测。

wi = uint32 (320);他= uint32 (240);ch = uint32 (3);文件名= fullfile (pwd,“ng1.png”);img = imread(文件名);Img = imresize(Img,[他,wi]);img = mat2ocv (img);%提取ROI进行预处理[Iori, imgpack, num, bbox] = myNDNet_Preprocess(img); / /上传数据%主行到主列的转换imgPacked2 = 0([4] 128128年,‘uint8’);c = 1:4i = 1:128j = 1:128 imgPacked2 (i, j c) = imgPacked((张)* 128 + (j - 1) +(颈- 1)* 128 * 128 + 1);结束结束结束%使用CNN对检测到的螺母进行分类成绩= 0(2、4);i = 1: num(分数(:,i)、速度)= hW.predict(单(imgPacked2(:,:我)),“个人资料”,“上”);结束
###完成写入输入激活。###运行单输入激活。Deep Learning Processor Profiler Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 12231156 0.05560 1 12231156 18.0 conv1 414021 0.00188 norm1 172325 0.00078 pool1 56747 0.00026 conv2 654112 0.00297 norm2 119403 0.00054 pool2 . Deep Learning Processor Profiler Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s43611 0.00020 conv3 777446 0.00353 conv4 595551 0.00271 conv5 404425 0.00184 pool5 17831 0.00008 fc6 1759699 0.00800 fc7 7030188 0.03196 fc8 185672 0.00084 * DL处理器的时钟频率为:220MHz
Iori =重塑(Iori,[1,他*wi*ch]);Bbox =重塑(Bbox, [1,16]);Scores =重塑(Scores, [1,8]);%插入用于后处理的注释out=myNDNet_后处理(Iori,num,bbox,scores,wi,he,ch);sz=[he-wi-ch];out=ocv2mat(out,sz);imshow(out)


              

为创建工作流对象trainedBlemDetNet网络

创建的对象dlhdl。工作流类。指定网络和位流名称。指定保存的预训练网络trainedblemDetNet随着网络。确保位流名称与您的目标数据类型和FPGA板匹配。本例中,目标FPGA板为Xilinx ZCU102 SOC板。位流使用单一数据类型。

hW = dlhdl。工作流(“网络”snet_blemdetnet,“比特流”,“zcu102_single”,“目标”hT)
hW =带有属性的工作流:Network: [1×1 SeriesNetwork] Bitstream: 'zcu102_single' ProcessorConfig: [] Target: [1×1 dlhdl. hW = []目标]

编制培训blemdetnet系列网络

的compile函数dlhdl。工作流对象。

编译
###编译用于深入学习FPGA原型的网络…####针对FPGA比特流zcu102#单…###该网络包括以下几层:1“imageinput”图像输入128×128×1图像与“zerocenter”标准化(软件层)2“conv_1”卷积20 5×5×1卷积与跨步[1]和填充[0 0 0 0 0](硬件层)3“relu_1”relu relu relu(硬件层)4“maxpool_1”最大池2×2最大池与跨步[2]和填充[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0(硬件层)5'交叉规范'交叉通道规范化交叉通道规范化每个元素5个通道(硬件层)6'conv_2'卷积20 5×5×20卷积带跨步[1]和填充[0 0 0 0 0](硬件层)7'relu_2'relu relu(硬件层)8'最大池2×2最大池带跨步[2]和填充[0 0 0 0 0 0 0](硬件层)9“fc_1”完全连接512完全连接层(硬件层)10“fc_2”完全连接2完全连接层(硬件层)11“softmax”softmax softmax(软件层)12“classoutput”分类输出交叉EntroPyex,带有“ng”和“ok”类(软件层)创建了3个内存区域。跳过:imageinput编译段:conv_1>>maxpool_2…编译段:conv_1>>maxpool_2…完成。编译段:fc_1>>fc_2…编译段:fc_1>>fc_2…完成。跳过:softmax跳过:类输出创建计划…….创建计划…完成。创建状态表…….创建状态表…完成。发射时间表…发射时间表…完成。发射状态表…完成。#####分配外部内存缓冲区:偏移量(名称偏移量)地址分配(空间)(uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu“0x00800000”“4.0 MB”“SchedulerDataOffset”“0x00c00000”“4.0 MB”“SystemBufferOffset”“0x01000000”“28.0 MB”“InstructionDataOffset”“0x02c00000”“4.0 MB”“ConvWeightDataOffset”“0x03000000”“4.0 MB”“FCWeightDataOffset”“0x03400000”“36.0 MB”“EndOffset”“0x05800000”“总计:88.0 MB”“网络编译完成。
ans =结构体字段:[1×1 struct]注册:[1×1 struct] syncstructions: [1×1 struct]

在FPGA上编程Bitstream并下载网络权重

要在Xilinx ZCU102 SoC硬件上部署网络,请运行dlhdl。工作流对象。该函数使用compile函数的输出,利用编程文件对FPGA板进行编程。它还下载了网络权重和偏差。deploy函数开始对FPGA设备进行编程,并显示进度消息和部署网络所需的时间。

hW.deploy
### FPGA位流编程已经被跳过,因为相同的位流已经加载到目标FPGA上。###加载权值到Conv处理器。### Conv权重加载。当前时间为16-Dec-2020 16:16:47 ###正在加载FC处理器权重。### 50%完成,当前时间是2020年12月16日16:16:48。### FC权重已加载。当前时间是2020年12月16日16:16:48

对一个图像运行预测

从附件中加载图像测试图像文件夹并调整图像大小以匹配网络图像输入层的尺寸。运行dlhdl。工作流对象从FPGA中检索和显示缺陷预测。

wi = uint32 (320);他= uint32 (240);ch = uint32 (3);文件名= fullfile (pwd,“ok1.png”);img = imread(文件名);Img = imresize(Img,[他,wi]);img = mat2ocv (img);%提取ROI进行预处理[Iori, imgpack, num, bbox] = myNDNet_Preprocess(img); / /上传数据%主行到主列的转换imgPacked2 = 0([4] 128128年,‘uint8’);c = 1:4i = 1:128j = 1:128 imgPacked2 (i, j c) = imgPacked((张)* 128 + (j - 1) +(颈- 1)* 128 * 128 + 1);结束结束结束%分类检测到的螺母使用CNN成绩= 0(2、4);i = 1: num(分数(:,i)、速度)= hW.predict(单(imgPacked2(:,:我)),“个人资料”,“上”);结束
###完成写入输入激活。###运行单输入激活。Deep Learning Processor Profiler Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 4892622 0.02224 1 4892622 45.0 conv_1 467921 0.00213 maxpool_1 188086 0.00085 crossnorm 159500 0.00072 conv_2 397561 0.00181 maxpool_2 41455 . maxpool_1 188086 0.00085 maxpool_1 188086 0.00085 crossnorm 159500 0.00072 conv_2 397561 0.00181 maxpool_2 414550.00019 fc_1 3614625 0.01643 fc_2 23355 0.00011
Iori =重塑(Iori,[1,他*wi*ch]);Bbox =重塑(Bbox, [1,16]);Scores =重塑(Scores, [1,8]);%为后处理插入注释out=myNDNet_后处理(Iori,num,bbox,scores,wi,he,ch);sz=[he-wi-ch];out=ocv2mat(out,sz);imshow(out)

量化部署trainedBlemDetNet网络

这个trainedBlemDetNet网络将性能提高到每秒45帧。部署网络的目标性能是100帧/秒,同时保持在目标资源利用预算之内。资源利用预算考虑了内存大小和板载IO等参数。虽然您可以通过选择更大的板来增加资源利用预算,但这样做会增加成本。相反,可以通过量化网络来提高部署的网络性能,并保持在资源利用预算之内。量化和部署trainedBlemDetNet网络。

将数据集加载为图像数据存储。的imageDatastore根据文件夹名称对图像进行标签并存储数据。将数据分为校准和验证数据集。使用50%的图像进行校准,50%的图像进行验证。通过使用校准和验证图像集的子集,加快校准和验证过程。

如果~isfile('dataSet.zip') url ='//www.tatmou.com/金宝appsupportfiles/dlhdl/dataSet.zip'; 韦伯萨夫('dataSet.zip'url);结束解压缩('dataSet.zip')解压缩('dataset.zip') imageData = imageDatastore(fullfile(“数据集”),...“IncludeSubfolders”符合事实的“FileExtensions”,“使用”,“LabelSource”,“foldernames”);[calibrationData, validationData] = splitEachLabel(imageData, 0.5,“随机”);calibrationData_reduced = calibrationData.subset (1:20);validationData_reduced = validationData.subset (1:1);

创建一个量子化网络使用数字量化器对象。将目标执行环境设置为FPGA。

dlQuantObj = dlquantizer (snet_blemdetnet,“ExecutionEnvironment”,FPGA的)
dlQuantObj = dlquantizer with properties: NetworkObject: [1×1 SeriesNetwork] ExecutionEnvironment: 'FPGA'

使用校准函数通过使用样本输入来练习网络,并收集范围信息。这个校准函数对网络进行操作,并在网络的卷积和全连接层中收集权重和偏差的动态范围,以及在网络的所有层中激活的动态范围。这个校准函数返回一个表。表的每一行包含量化网络的一个可学习参数的范围信息。

dlQuantObj.校准(校准数据减少)
ans =21日×5表优化层名称网络层名称可学的/激活MinValue MaxValue  ____________________________ __________________ ________________________ __________ _________ {' conv_1_Weights’}{‘conv_1}“权重”-0.29022 - 0.21403{‘conv_1_Bias}{‘conv_1}“偏见”-0.021907 - 0.0053595{‘conv_2_Weights}{‘conv_2}“权重”-0.10499 - 0.13732{'conv_2_Bias' } {'conv_2' } "Bias" -0.010084 0.025773 {'fc_1_Weights' } {'fc_1' } "Weights" -0.051599 0.054506 {'fc_1_Bias' } {'fc_1' } "Bias" -0.0048897 0.0072463 {'fc_2_Weights' } {'fc_2' } "Weights" -0.071356 0.064882 {'fc_2_Bias' } {'fc_2' } "Bias" -0.062086 0.062084 {'imageinput' } {'imageinput'} "Activations" 0 255 {'imageinput_normalization'} {'imageinput'} "Activations" -184.37 241.75 {'conv_1' } {'conv_1' } "Activations" -112.18 150.51 {'relu_1' } {'relu_1' } "Activations" 0 150.51 {'maxpool_1' } {'maxpool_1' } "Activations" 0 150.51 {'crossnorm' } {'crossnorm' } "Activations" 0 113.27 {'conv_2' } {'conv_2' } "Activations" -117.79 67.125 {'relu_2' } {'relu_2' } "Activations" 0 67.125 ⋮

创建的对象dlhdl。工作流类。指定网络和位流名称。指定保存的预训练量化trainedblemDetNet对象dlQuantObj作为网络。确保比特流名称与数据类型和目标FPGA板匹配。在本例中,目标FPGA板是Xilinx ZCU102 SOC板。比特流使用int8数据类型。

hW = dlhdl。工作流(“网络”,dlQuantObj,“比特流”,“zcu102_int8”,“目标”hT);

要编译量化网络,运行的编译函数dlhdl。工作流对象。

编译(“InputFrameNumberLimit”, 30)
###编译网络深度学习FPGA原型…### FPGA bitstream zcu102_int8…###网络包括以下几层:1“imageinput”图像输入128×128×1图像“zerocenter”正常化(SW层)2的conv_1卷积20 5×5×1步[1]和填充的卷积[0 0 0 0](HW层)3的relu_1 ReLU ReLU (HW层)4“maxpool_1”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0](HW层)5 crossnorm横通道正常化交叉道归一化与5频道/元素(HW层)6的conv_2卷积20 5×5×20旋转步[1]和填充[0 0 0 0](HW层)7的relu_2 ReLU ReLU (HW层)8“maxpool_2”马克斯池2×2马克斯池步(2 - 2)和填充[0 0 0 0](HW层)9 fc_1完全连接512完全连接层(HW层)10 'fc_2' Fully Connected 2 fully connected layer (HW Layer) 11 'softmax' Softmax softmax (SW Layer) 12 'classoutput' Classification Output crossentropyex with classes 'ng' and 'ok' (SW Layer) 3 Memory Regions created. Skipping: imageinput Compiling leg: conv_1>>maxpool_2 ... Compiling leg: conv_1>>maxpool_2 ... complete. Compiling leg: fc_1>>fc_2 ... Compiling leg: fc_1>>fc_2 ... complete. Skipping: softmax Skipping: classoutput Creating Schedule... ......... Creating Schedule...complete. Creating Status Table... ........ Creating Status Table...complete. Emitting Schedule... ...... Emitting Schedule...complete. Emitting Status Table... .......... Emitting Status Table...complete. ### Allocating external memory buffers: offset_name offset_address allocated_space _______________________ ______________ ________________ "InputDataOffset" "0x00000000" "16.0 MB" "OutputResultOffset" "0x01000000" "4.0 MB" "SchedulerDataOffset" "0x01400000" "4.0 MB" "SystemBufferOffset" "0x01800000" "28.0 MB" "InstructionDataOffset" "0x03400000" "4.0 MB" "ConvWeightDataOffset" "0x03800000" "4.0 MB" "FCWeightDataOffset" "0x03c00000" "12.0 MB" "EndOffset" "0x04800000" "Total: 72.0 MB" ### Network compilation complete.
ans =结构体字段:[1×1 struct]注册:[1×1 struct] syncstructions: [1×1 struct]

要在Xilinx ZCU102 SoC硬件上部署网络,请运行dlhdl。工作流对象。该函数使用compile函数的输出,利用编程文件对FPGA板进行编程。它还下载了网络权重和偏差。deploy函数开始对FPGA设备进行编程,并显示进度消息和部署网络所需的时间。

hW.deploy
###使用以太网编程FPGA Bitstream…下载目标FPGA设备配置通过以太网到SD卡…#将/tmp/hdlcoder_rd拷贝到/mnt/hdlcoder_rd。bit to /mnt/hdlcoder_rd #设置Bitstream为hdlcoder_rd/hdlcoder_system。#复制devicetree_dlhdl. bit #复制devicetree_dlhdl. bit #复制devicetree_dlhdl。dtb为/mnt/hdlcoder_rd #设置Devicetree为hdlcoder_rd/devicetree_dlhdl。dtb # Set boot for Reference Design: ' axis - stream DDR Memory Access: 3-AXIM'现在系统将重新启动以使持久更改生效。系统正在重新启动。

. . . . .### FPGA位流编程已成功完成###加载权值到Conv处理器。### Conv权重加载。###正在加载FC处理器的权重。### FC权重已加载。当前时间是2020年12月16日16:18:03

从附件中加载图像测试图像文件夹并调整图像大小以匹配网络图像输入层的尺寸。运行dlhdl。工作流对象从FPGA中检索和显示缺陷预测。

wi = uint32 (320);他= uint32 (240);ch = uint32 (3);文件名= fullfile (pwd,“ok1.png”);img = imread(文件名);Img = imresize(Img,[他,wi]);img = mat2ocv (img);%提取ROI进行预处理[Iori, imgpack, num, bbox] = myNDNet_Preprocess(img); / /上传数据% row-major > column-major转换imgPacked2 = 0([4] 128128年,‘uint8’);c = 1:4i = 1:128j = 1:128 imgPacked2 (i, j c) = imgPacked((张)* 128 + (j - 1) +(颈- 1)* 128 * 128 + 1);结束结束结束%分类检测到的螺母使用CNN成绩= 0(2、4);i = 1: num(分数(:,i)、速度)= hW.predict(单(imgPacked2(:,:我)),“个人资料”,“上”);结束
###完成写入输入激活。###运行单输入激活。深度学习处理器Profiler性能结果LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 1754969 0.00798 1 1754969 125.4 conv_1 271340 0.00123 maxpool_1 87533 0.00040 crossnorm 125737 0.00057 conv_2 149972 0.00068 maxpool_2 196570.00009 fc_1 1085683 0.00493 fc_2 14928 0.00007 * DL处理器的时钟频率为:220MHz
Iori =重塑(Iori,[1,他*wi*ch]);Bbox =重塑(Bbox, [1,16]);Scores =重塑(Scores, [1,8]);%插入用于后处理的注释out=myNDNet_后处理(Iori,num,bbox,scores,wi,he,ch);sz=[he-wi-ch];out=ocv2mat(out,sz);imshow(out)

要测试量化网络是否可以识别所有测试用例,请部署一个附加图像,调整图像大小以匹配网络图像输入层尺寸,并运行dlhdl。工作流对象从FPGA中检索和显示缺陷预测。

wi = uint32 (320);他= uint32 (240);ch = uint32 (3);文件名= fullfile (pwd,“okng.png”);img = imread(文件名);Img = imresize(Img,[他,wi]);img = mat2ocv (img);%提取ROI进行预处理[Iori, imgpack, num, bbox] = myNDNet_Preprocess(img); / /上传数据% row-major > column-major转换imgPacked2 = 0([4] 128128年,‘uint8’);c = 1:4i = 1:128j = 1:128 imgPacked2 (i, j c) = imgPacked((张)* 128 + (j - 1) +(颈- 1)* 128 * 128 + 1);结束结束结束%分类检测到的螺母使用CNN成绩= 0(2、4);i = 1: num(分数(:,i)、速度)= hW.predict(单(imgPacked2(:,:我)),“个人资料”,“上”);结束
###完成写入输入激活。###运行单输入激活。深度学习处理器Profiler性能结果LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 1754614 0.00798 1 1754614 125.4 conv_1 271184 0.00123 maxpool_1 87557 0.00040 crossnorm 125768 0.00057 conv_2 149819 0.00068 maxpool_2 196020.00009 fc_1 1085664 0.00493 fc_2 14930 0.00007 * DL处理器的时钟频率为:220MHz ###完成写入输入激活###运行单输入激活。Deep Learning Processor Profiler Performance Results LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s ------------- ------------- --------- --------- --------- Network 1754486 0.00797 1 1754486 125.4 conv_1 271014 0.00123 maxpool_1 87662 0.00040 crossnorm 125835 0.00057 conv_2 149789 0.00068 maxpool_2 19661 . maxpool_2的性能数据如下0.00009 fc_1 1085505 0.00493 fc_2 14930 0.00007 * DL处理器的时钟频率为:220MHz
Iori =重塑(Iori,[1,他*wi*ch]);Bbox =重塑(Bbox, [1,16]);Scores =重塑(Scores, [1,8]);%插入用于后处理的注释out=myNDNet_后处理(Iori,num,bbox,scores,wi,he,ch);sz=[he-wi-ch];out=ocv2mat(out,sz);imshow(out)

量化网络将性能从每秒45帧提高到125帧,并将部署的网络大小从88 MB减少到72 MB。