В этом примере показано, как развернуть настраиваемую обучаемую сеть серии для обнаружения дефектов в таких объектах, как шестиугольные гайки. Пользовательские сети были обучены с использованием трансфертного обучения. Transfer learning обычно используется в приложениях для глубокого обучения. Предварительно подготовленную сеть можно использовать в качестве отправной точки для изучения новой задачи. Точная настройка сети с обучением переносу обычно намного быстрее и проще, чем обучение сети с произвольно инициализированными весами с нуля. Вы можете быстро перенести изученные функции в новую задачу, используя меньшее количество обучающих сигналов. В этом примере используются две обученные сети серии trainedDefNet.mat и trainedBlemDetNet.mat.
Комплект для разработки Xilinx ZCU102 SoC
Пакет Toolbox™Support HDL для глубокого обучения для Xilinx FPGA и SoC
Глубокое обучение Toolbox™
Глубокое обучение HDL Toolbox™
Загрузка и загрузка пользовательских предварительно подготовленных сетей серии trainedDefNet и trainedBlemDetNet, введите:
if ~isfile('trainedDefNet.mat') url = 'https://www.mathworks.com/supportfiles/dlhdl/trainedDefNet.mat'; websave('trainedDefNet.mat',url); end net1 = load('trainedDefNet.mat'); snet_defnet = net1.custom_alexnet
snet_defnet =
SeriesNetwork with properties:
Layers: [25×1 nnet.cnn.layer.Layer]
InputNames: {'data'}
OutputNames: {'output'}
Проанализировать snet_defnet слои.
analyzeNetwork(snet_defnet)

if ~isfile('trainedBlemDetNet.mat') url = 'https://www.mathworks.com/supportfiles/dlhdl/trainedBlemDetNet.mat'; websave('trainedBlemDetNet.mat',url); end net2 = load('trainedBlemDetNet.mat'); snet_blemdetnet = net2.convnet
snet_blemdetnet =
SeriesNetwork with properties:
Layers: [12×1 nnet.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.Target('Xilinx','Interface','Ethernet')
hT =
Target with properties:
Vendor: 'Xilinx'
Interface: Ethernet
IPAddress: '192.168.1.101'
Username: 'root'
Port: 22
Создание объекта dlhdl.Workflow класс. При создании объекта укажите сеть и имя битового потока. Укажите сохраненный предварительно обученный trainedDefNet как сеть. Убедитесь, что имя битового потока соответствует типу данных и целевой плате FPGA. В этом примере целевой платой FPGA является плата Xilinx ZCU102 SOC. Битовый поток использует один тип данных.
hW = dlhdl.Workflow('Network',snet_defnet,'Bitstream','zcu102_single','Target',hT)
hW =
Workflow with properties:
Network: [1×1 SeriesNetwork]
Bitstream: 'zcu102_single'
ProcessorConfig: []
Target: [1×1 dlhdl.Target]
Для компиляции сети серии Defnet выполните функцию компиляции dlhdl.Workflow объект.
hW.compile
### Compiling network for Deep Learning FPGA prototyping ...
### Targeting FPGA bitstream zcu102_single ...
### The network includes the following layers:
1 'data' Image Input 128×128×1 images with 'zerocenter' normalization (SW Layer)
2 'conv1' Convolution 96 11×11×1 convolutions with stride [4 4] and padding [0 0 0 0] (HW Layer)
3 'relu1' ReLU ReLU (HW Layer)
4 'norm1' Cross Channel Normalization cross channel normalization with 5 channels per element (HW Layer)
5 'pool1' Max Pooling 3×3 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
6 'conv2' Grouped Convolution 2 groups of 128 5×5×48 convolutions with stride [1 1] and padding [2 2 2 2] (HW Layer)
7 'relu2' ReLU ReLU (HW Layer)
8 'norm2' Cross Channel Normalization cross channel normalization with 5 channels per element (HW Layer)
9 'pool2' Max Pooling 3×3 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
10 'conv3' Convolution 384 3×3×256 convolutions with stride [1 1] and padding [1 1 1 1] (HW Layer)
11 'relu3' ReLU ReLU (HW Layer)
12 'conv4' Grouped Convolution 2 groups of 192 3×3×192 convolutions with stride [1 1] and padding [1 1 1 1] (HW Layer)
13 'relu4' ReLU ReLU (HW Layer)
14 'conv5' Grouped Convolution 2 groups of 128 3×3×192 convolutions with stride [1 1] and padding [1 1 1 1] (HW Layer)
15 'relu5' ReLU ReLU (HW Layer)
16 'pool5' Max Pooling 3×3 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
17 'fc6' Fully Connected 4096 fully connected layer (HW Layer)
18 'relu6' ReLU ReLU (HW Layer)
19 'drop6' Dropout 50% dropout (HW Layer)
20 'fc7' Fully Connected 4096 fully connected layer (HW Layer)
21 'relu7' ReLU ReLU (HW Layer)
22 'drop7' Dropout 50% dropout (HW Layer)
23 'fc8' Fully Connected 2 fully connected layer (HW Layer)
24 'prob' Softmax softmax (SW Layer)
25 'output' Classification Output crossentropyex with classes 'ng' and 'ok' (SW Layer)
3 Memory Regions created.
Skipping: data
Compiling leg: 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 = struct with fields:
weights: [1×1 struct]
instructions: [1×1 struct]
registers: [1×1 struct]
syncInstructions: [1×1 struct]
Для развертывания сети на оборудовании Xilinx ZCU102 SoC выполните функцию развертывания dlhdl.Workflow объект. Эта функция использует выходные данные функции компиляции для программирования платы FPGA с помощью файла программирования. Он также загружает веса сети и отклонения. Функция развертывания запускает программирование устройства FPGA, отображает сообщения о ходе выполнения и время, необходимое для развертывания сети.
hW.deploy
### Programming FPGA Bitstream using Ethernet... Downloading target FPGA device configuration over Ethernet to SD card ... # Copied /tmp/hdlcoder_rd to /mnt/hdlcoder_rd # Copying Bitstream hdlcoder_system.bit to /mnt/hdlcoder_rd # Set Bitstream to hdlcoder_rd/hdlcoder_system.bit # Copying Devicetree devicetree_dlhdl.dtb to /mnt/hdlcoder_rd # Set Devicetree to hdlcoder_rd/devicetree_dlhdl.dtb # Set up boot for Reference Design: 'AXI-Stream DDR Memory Access : 3-AXIM' Downloading target FPGA device configuration over Ethernet to SD card done. The system will now reboot for persistent changes to take effect. System is rebooting . . . . . . ### Programming the FPGA bitstream has been completed successfully. ### Loading weights to Conv Processor. ### Conv Weights loaded. 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.Workflow объект для извлечения и отображения прогноза дефектов из FPGA.
wi = uint32(320); he = uint32(240); ch = uint32(3); filename = fullfile(pwd,'ng1.png'); img=imread(filename); img = imresize(img, [he, wi]); img = mat2ocv(img); % Extract ROI for preprocessing [Iori, imgPacked, num, bbox] = myNDNet_Preprocess(img); % row-major > column-major conversion imgPacked2 = zeros([128,128,4],'uint8'); for c = 1:4 for i = 1:128 for j = 1:128 imgPacked2(i,j,c) = imgPacked((i-1)*128 + (j-1) + (c-1)*128*128 + 1); end end end % Classify detected nuts by using CNN scores = zeros(2,4); for i = 1:num [scores(:,i), speed] = hW.predict(single(imgPacked2(:,:,i)),'Profile','on'); end
### Finished writing input activations.
### Running single input activations.
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 43611 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
* The clock frequency of the DL processor is: 220MHz
Iori = reshape(Iori, [1, he*wi*ch]);
bbox = reshape(bbox, [1,16]);
scores = reshape(scores, [1, 8]);
% Insert an annotation for postprocessing
out = myNDNet_Postprocess(Iori, num, bbox, scores, wi, he, ch);
sz = [he wi ch];
out = ocv2mat(out,sz);
imshow(out)
Создание объекта dlhdl.Workflow класс. При создании объекта укажите сеть и имя битового потока. Укажите сохраненный предварительно обученный trainedblemDetNet как сеть. Убедитесь, что имя битового потока соответствует типу данных и целевой плате FPGA. В этом примере целевой платой FPGA является плата Xilinx ZCU102 SOC. Битовый поток использует один тип данных.
hW = dlhdl.Workflow('Network',snet_blemdetnet,'Bitstream','zcu102_single','Target',hT)
hW =
Workflow with properties:
Network: [1×1 SeriesNetwork]
Bitstream: 'zcu102_single'
ProcessorConfig: []
Target: [1×1 dlhdl.Target]
Для компиляции trainedBlemDetNet series network, запустите функцию компиляции dlhdl.Workflow объект.
hW.compile
### Compiling network for Deep Learning FPGA prototyping ...
### Targeting FPGA bitstream zcu102_single ...
### The network includes the following layers:
1 'imageinput' Image Input 128×128×1 images with 'zerocenter' normalization (SW Layer)
2 'conv_1' Convolution 20 5×5×1 convolutions with stride [1 1] and padding [0 0 0 0] (HW Layer)
3 'relu_1' ReLU ReLU (HW Layer)
4 'maxpool_1' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
5 'crossnorm' Cross Channel Normalization cross channel normalization with 5 channels per element (HW Layer)
6 'conv_2' Convolution 20 5×5×20 convolutions with stride [1 1] and padding [0 0 0 0] (HW Layer)
7 'relu_2' ReLU ReLU (HW Layer)
8 'maxpool_2' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
9 'fc_1' Fully Connected 512 fully connected layer (HW Layer)
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 = struct with fields:
weights: [1×1 struct]
instructions: [1×1 struct]
registers: [1×1 struct]
syncInstructions: [1×1 struct]
Для развертывания сети на оборудовании Xilinx ZCU102 SoC выполните функцию развертывания dlhdl.Workflow объект. Эта функция использует выходные данные функции компиляции для программирования платы FPGA с помощью файла программирования. Он также загружает веса сети и отклонения. Функция развертывания запускает программирование устройства FPGA, отображает сообщения о ходе выполнения и время, необходимое для развертывания сети.
hW.deploy
### FPGA bitstream programming has been skipped as the same bitstream is already loaded on the target FPGA. ### Loading weights to Conv Processor. ### Conv Weights loaded. Current time is 16-Dec-2020 16:16:47 ### Loading weights to FC Processor. ### 50% finished, current time is 16-Dec-2020 16:16:48. ### FC Weights loaded. Current time is 16-Dec-2020 16:16:48
Загрузить изображение из подключенного testImages , изменить размер изображения в соответствии с размерами слоя ввода сетевого изображения и запустить функцию прогнозирования dlhdl.Workflow объект для извлечения и отображения прогноза дефектов из FPGA.
wi = uint32(320); he = uint32(240); ch = uint32(3); filename = fullfile(pwd,'ok1.png'); img=imread(filename); img = imresize(img, [he, wi]); img = mat2ocv(img); % Extract ROI for preprocessing [Iori, imgPacked, num, bbox] = myNDNet_Preprocess(img); % row-major > column-major conversion imgPacked2 = zeros([128,128,4],'uint8'); for c = 1:4 for i = 1:128 for j = 1:128 imgPacked2(i,j,c) = imgPacked((i-1)*128 + (j-1) + (c-1)*128*128 + 1); end end end % classify detected nuts by using CNN scores = zeros(2,4); for i = 1:num [scores(:,i), speed] = hW.predict(single(imgPacked2(:,:,i)),'Profile','on'); end
### Finished writing input activations.
### Running single input activations.
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 0.00019
fc_1 3614625 0.01643
fc_2 23355 0.00011
* The clock frequency of the DL processor is: 220MHz
Iori = reshape(Iori, [1, he*wi*ch]);
bbox = reshape(bbox, [1,16]);
scores = reshape(scores, [1, 8]);
% Insert annotation for postprocessing
out = myNDNet_Postprocess(Iori, num, bbox, scores, wi, he, ch);
sz = [he wi ch];
out = ocv2mat(out,sz);
imshow(out)
trainedBlemDetNet Сеть trainedBlemDetNet сеть повышает производительность до 45 кадров в секунду. Целевая производительность развернутой сети составляет 100 кадров в секунду, оставаясь в пределах целевого бюджета использования ресурсов. Бюджет использования ресурсов учитывает такие параметры, как размер памяти, ввод-вывод на плате и т.д. Увеличение использования ресурсов может означать выбор более крупного совета директоров, который может стоить больше денег. Увеличьте производительность развернутой сети и оставайтесь в рамках бюджета использования ресурсов, квантуя сеть. Квантование и развертывание trainedBlemDetNet сеть:
Загрузите набор данных как хранилище данных образа. imageDatastore помечает изображения на основе имен папок и сохраняет данные. Разделите данные на наборы данных калибровки и проверки. Используйте 50% изображений для калибровки и 50% изображений для проверки. Ускорьте процесс калибровки и проверки с помощью подмножества наборов изображений калибровки и проверки.
if ~isfile('dataSet.zip') url = 'https://www.mathworks.com/supportfiles/dlhdl/dataSet.zip'; websave('dataSet.zip',url); end unzip('dataSet.zip') unzip('dataset.zip') imageData = imageDatastore(fullfile('dataset'),... 'IncludeSubfolders',true,'FileExtensions','.PNG','LabelSource','foldernames'); [calibrationData, validationData] = splitEachLabel(imageData, 0.5,'randomized'); 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'
Используйте calibrate функция для выполнения сети с входами образцов и сбора информации о диапазоне. calibrate функция выполняет сеть и собирает динамические диапазоны весов и смещений в свертке и полностью соединенных уровнях сети и динамические диапазоны активизаций во всех уровнях сети. calibrate функция возвращает таблицу. Каждая строка таблицы содержит информацию о диапазоне для обучаемого параметра квантованной сети.
dlQuantObj.calibrate(calibrationData_reduced)
ans=21×5 table
Optimized Layer Name Network Layer Name Learnables / Activations MinValue MaxValue
____________________________ __________________ ________________________ __________ _________
{'conv_1_Weights' } {'conv_1' } "Weights" -0.29022 0.21403
{'conv_1_Bias' } {'conv_1' } "Bias" -0.021907 0.0053595
{'conv_2_Weights' } {'conv_2' } "Weights" -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.Workflow класс. При создании объекта укажите сеть и имя битового потока. Укажите сохраненный предварительно обученный квантованный trainedblemDetNet объект dlQuantObj как сеть. Убедитесь, что имя битового потока соответствует типу данных и целевой плате FPGA. В этом примере целевой платой FPGA является плата Xilinx ZCU102 SOC. Битовый поток использует тип данных int8.
hW = dlhdl.Workflow('Network', dlQuantObj, 'Bitstream', 'zcu102_int8','Target',hT);
Чтобы скомпилировать квантованную сеть, выполните функцию компиляции dlhdl.Workflow объект.
hW.compile('InputFrameNumberLimit',30)### Compiling network for Deep Learning FPGA prototyping ...
### Targeting FPGA bitstream zcu102_int8 ...
### The network includes the following layers:
1 'imageinput' Image Input 128×128×1 images with 'zerocenter' normalization (SW Layer)
2 'conv_1' Convolution 20 5×5×1 convolutions with stride [1 1] and padding [0 0 0 0] (HW Layer)
3 'relu_1' ReLU ReLU (HW Layer)
4 'maxpool_1' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
5 'crossnorm' Cross Channel Normalization cross channel normalization with 5 channels per element (HW Layer)
6 'conv_2' Convolution 20 5×5×20 convolutions with stride [1 1] and padding [0 0 0 0] (HW Layer)
7 'relu_2' ReLU ReLU (HW Layer)
8 'maxpool_2' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
9 'fc_1' Fully Connected 512 fully connected layer (HW Layer)
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 = struct with fields:
weights: [1×1 struct]
instructions: [1×1 struct]
registers: [1×1 struct]
syncInstructions: [1×1 struct]
Для развертывания сети на оборудовании Xilinx ZCU102 SoC выполните функцию развертывания dlhdl.Workflow объект. Эта функция использует выходные данные функции компиляции для программирования платы FPGA с помощью файла программирования. Он также загружает веса сети и отклонения. Функция развертывания запускает программирование устройства FPGA, отображает сообщения о ходе выполнения и время, необходимое для развертывания сети.
hW.deploy
### Programming FPGA Bitstream using Ethernet... Downloading target FPGA device configuration over Ethernet to SD card ... # Copied /tmp/hdlcoder_rd to /mnt/hdlcoder_rd # Copying Bitstream hdlcoder_system.bit to /mnt/hdlcoder_rd # Set Bitstream to hdlcoder_rd/hdlcoder_system.bit # Copying Devicetree devicetree_dlhdl.dtb to /mnt/hdlcoder_rd # Set Devicetree to hdlcoder_rd/devicetree_dlhdl.dtb # Set up boot for Reference Design: 'AXI-Stream DDR Memory Access : 3-AXIM' Downloading target FPGA device configuration over Ethernet to SD card done. The system will now reboot for persistent changes to take effect. System is rebooting .

. . . . . ### Programming the FPGA bitstream has been completed successfully. ### Loading weights to Conv Processor. ### Conv Weights loaded. Current time is 16-Dec-2020 16:18:03 ### Loading weights to FC Processor. ### FC Weights loaded. Current time is 16-Dec-2020 16:18:03
Загрузить изображение из подключенного testImages , изменить размер изображения в соответствии с размерами слоя ввода сетевого изображения и запустить функцию прогнозирования dlhdl.Workflow объект для извлечения и отображения прогноза дефектов из FPGA.
wi = uint32(320); he = uint32(240); ch = uint32(3); filename = fullfile(pwd,'ok1.png'); img=imread(filename); img = imresize(img, [he, wi]); img = mat2ocv(img); % Extract ROI for preprocessing [Iori, imgPacked, num, bbox] = myNDNet_Preprocess(img); % row-major > column-major conversion imgPacked2 = zeros([128,128,4],'uint8'); for c = 1:4 for i = 1:128 for j = 1:128 imgPacked2(i,j,c) = imgPacked((i-1)*128 + (j-1) + (c-1)*128*128 + 1); end end end % classify detected nuts by using CNN scores = zeros(2,4); for i = 1:num [scores(:,i), speed] = hW.predict(single(imgPacked2(:,:,i)),'Profile','on'); end
### Finished writing input activations.
### Running single input activations.
Deep Learning Processor Profiler Performance Results
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 19657 0.00009
fc_1 1085683 0.00493
fc_2 14928 0.00007
* The clock frequency of the DL processor is: 220MHz
Iori = reshape(Iori, [1, he*wi*ch]);
bbox = reshape(bbox, [1,16]);
scores = reshape(scores, [1, 8]);
% Insert an annotation for postprocessing
out = myNDNet_Postprocess(Iori, num, bbox, scores, wi, he, ch);
sz = [he wi ch];
out = ocv2mat(out,sz);
imshow(out)
Чтобы проверить, что квантованная сеть может идентифицировать все тестовые случаи, развернуть дополнительное изображение, изменить размер изображения в соответствии с размерами входного слоя сетевого изображения и запустить функцию прогнозирования dlhdl.Workflow объект для извлечения и отображения прогноза дефектов из FPGA.
wi = uint32(320); he = uint32(240); ch = uint32(3); filename = fullfile(pwd,'okng.png'); img=imread(filename); img = imresize(img, [he, wi]); img = mat2ocv(img); % Extract ROI for preprocessing [Iori, imgPacked, num, bbox] = myNDNet_Preprocess(img); % row-major > column-major conversion imgPacked2 = zeros([128,128,4],'uint8'); for c = 1:4 for i = 1:128 for j = 1:128 imgPacked2(i,j,c) = imgPacked((i-1)*128 + (j-1) + (c-1)*128*128 + 1); end end end % classify detected nuts by using CNN scores = zeros(2,4); for i = 1:num [scores(:,i), speed] = hW.predict(single(imgPacked2(:,:,i)),'Profile','on'); end
### Finished writing input activations.
### Running single input activations.
Deep Learning Processor Profiler Performance Results
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 19602 0.00009
fc_1 1085664 0.00493
fc_2 14930 0.00007
* The clock frequency of the DL processor is: 220MHz
### Finished writing input activations.
### Running single input activations.
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 0.00009
fc_1 1085505 0.00493
fc_2 14930 0.00007
* The clock frequency of the DL processor is: 220MHz
Iori = reshape(Iori, [1, he*wi*ch]);
bbox = reshape(bbox, [1,16]);
scores = reshape(scores, [1, 8]);
% Insert an annotation for postprocessing
out = myNDNet_Postprocess(Iori, num, bbox, scores, wi, he, ch);
sz = [he wi ch];
out = ocv2mat(out,sz);
imshow(out)
Квантование сети повышает производительность с 45 кадров в секунду до 125 кадров в секунду и уменьшает размер развернутой сети с 88 МБ до 72 МБ.