主要内容

缺陷检测

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

先决条件

  • Xilinx ZCU102 SoC开发工具包

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

  • 深度学习工具箱™

  • 深度学习HDL工具箱™

负载Pretrained网络

下载和加载定制的预先训练的系列网络trainedDefNettrainedBlemDetNet,输入:

如果~ isfile (“trainedDefNet.mat”) url =“//www.tatmou.com/金宝appsupportfiles/dlhdl/trainedDefNet.mat”;websave (“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'}

分析snet_defnet层。

analyzeNetwork (snet_defnet)

如果~ isfile (“trainedBlemDetNet.mat”) url =“//www.tatmou.com/金宝appsupportfiles/dlhdl/trainedBlemDetNet.mat”;websave (“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和Ethernet。要使用JTAG连接,请安装Xilinx™Vivado™Design Suite 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系列网络

编译训练有素的defnet系列网络,运行编译功能dlhdl。工作流对象。

hW.compile
###编译网络深度学习FPGA原型…### FPGA bitstream zcu102_single…###网络包括以下几层:1的数据图像输入128×128×1图像“zerocenter”正常化(SW层)2 conv1卷积96年11×11×1旋转步[4 4]和填充[0 0 0 0](HW层)3的relu1 ReLU ReLU (HW层)4 norm1的横通道正常化横通道正常化与5频道/元素(HW层)5 pool1马克斯池3×3马克斯池与步幅[2 2]和填充[0 0 0 0](HW层)6“conv2”分组卷积2组128 5×5×48旋转步[1]和填充[2 2 2 2](HW层)7的relu2 ReLU ReLU (HW层)8“norm2”横通道正常化横通道正常化与5频道/元素(HW层)9“pool2”马克斯池3×3马克斯池步(2 - 2)和填充[0 0 0 0]conv3的卷积(HW层)384 3×3×256旋转步[1]和填充[1 1 1 1](HW层)11的relu3 ReLU ReLU (HW层)12“conv4”分组卷积2组192 3×3×192旋转步[1]和填充[1 1 1 1](HW层)13的relu4 ReLU ReLU (HW层)14“conv5”分组卷积2组128 3×3×192旋转步[1]和填充[1 1 1 1](HW层)15 ' relu5 ReLU ReLU (HW层)16“pool5”马克斯池3×3马克斯池步(2 - 2)和填充[0 0 0 0](HW层)17 fc6完全连接4096完全连接层(HW层)18“relu6”ReLU ReLU (HW层)19 drop6辍学50%辍学(HW层)20 fc7完全连接4096完全连接层(HW层)21 ' relu7 ReLU ReLU (HW层)22“drop7”辍学50%辍学(HW层)23“fc8”完全连接2完全连接层(HW层)24“概率”Softmax Softmax(层)西南25“输出”分类输出crossentropyex类“ng”和“ok”(SW层)3内存创建区域。编译段:conv1>>pool5… Compiling leg: conv1>>pool5 ... complete. Compiling leg: fc6>>fc8 ... Compiling leg: fc6>>fc8 ... complete. Skipping: prob Skipping: output 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" "8.0 MB" "OutputResultOffset" "0x00800000" "4.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" "Total: 144.0 MB" ### Network compilation complete.
ans =结构体字段:[1×1 struct]注册:[1×1 struct] syncstructions: [1×1 struct]

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

当需要在Xilinx ZCU102 SoC硬件上部署网络时,需要运行Xilinx的deploy功能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

运行一个图像的预测

从附件中加载图像testImages文件夹,调整图像大小以匹配网络图像输入层尺寸,并运行预测功能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); / /上传数据% 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(:,:我)),“配置文件”“上”);结束
###完成写入输入激活。###运行单输入激活。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_Postprocess(Iori, num, bbox, scores, wi, he, ch); / /输出Sz = [he wi ch];出来= ocv2mat(深圳);imshow(出)


              

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

对象的对象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系列网络

来编译trainedBlemDetNet系列网络,运行编译功能dlhdl。工作流对象。

hW.compile
###编译网络深度学习FPGA原型…### FPGA bitstream zcu102_single…###网络包括以下几层: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" "8.0 MB" "OutputResultOffset" "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" "Total: 88.0 MB" ### Network compilation complete.
ans =结构体字段:[1×1 struct]注册:[1×1 struct] syncstructions: [1×1 struct]

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

当需要在Xilinx ZCU102 SoC硬件上部署网络时,需要运行Xilinx的deploy功能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

运行一个图像的预测

从附件中加载图像testImages文件夹,调整图像大小以匹配网络图像输入层尺寸,并运行预测功能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(:,:我)),“配置文件”“上”);结束
###完成写入输入激活。###运行单输入激活。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_Postprocess(Iori, num, bbox, scores, wi, he, ch); / /输出Sz = [he wi ch];出来= ocv2mat(深圳);imshow(出)

数字转换和部署trainedBlemDetNet网络

trainedBlemDetNet网络将性能提高到每秒45帧。部署网络的目标性能是100帧/秒,同时保持在目标资源利用预算之内。资源利用预算考虑内存大小、板上IO等参数。增加资源利用率可能意味着选择更大的板,这可能会花费更多的钱。通过量化网络,提高已部署网络的性能,并保持在资源利用预算之内。量化和部署trainedBlemDetNet网络:

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

如果~ isfile (“dataSet.zip”) url =“//www.tatmou.com/金宝appsupportfiles/dlhdl/dataSet.zip”;websave (“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);
  • 创建一个量子化网络使用dlquantizer对象。设置目标执行环境为FPGA。

dlQuantObj = dlquantizer (snet_blemdetnet,“ExecutionEnvironment”FPGA的
dlQuantObj = dlquantizer with properties: NetworkObject: [1×1 SeriesNetwork] ExecutionEnvironment: 'FPGA'
  • 使用校准函数用样本输入来练习网络,并收集范围信息。的校准函数对网络进行操作,并在网络的卷积和全连接层中收集权重和偏差的动态范围,以及在网络的所有层中激活的动态范围。的校准函数返回一个表。表的每一行包含量化网络的一个可学习参数的范围信息。

dlQuantObj.calibrate (calibrationData_reduced)
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。工作流对象。

hW.compile (“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硬件上部署网络时,需要运行Xilinx的deploy功能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
  • 从附件中加载图像testImages文件夹,调整图像大小以匹配网络图像输入层尺寸,并运行预测功能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_Postprocess(Iori, num, bbox, scores, wi, he, ch); / /输出Sz = [he wi ch];出来= ocv2mat(深圳);imshow(出)

为了测试量化网络是否能够识别所有测试用例,部署额外的图像,调整图像的大小以匹配网络图像的输入层尺寸,并运行预测函数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_Postprocess(Iori, num, bbox, scores, wi, he, ch); / /输出Sz = [he wi ch];出来= ocv2mat(深圳);imshow(出)

通过网络量化,可以将网络的性能从每秒45帧提高到每秒125帧,同时可以将部署的网络大小从88mb降低到72mb。