В этом примере показано, как создать, скомпилировать и развернуть dlhdl.Workflow объект, который имеет рукописную сеть серии обнаружения символов в качестве объекта сети с помощью пакета поддержки Deep Learning HDL Toolbox™ для Xilinx FPGA и SoC. Используйте MATLAB ®, чтобы получить результаты предсказания с целевого устройства .
Xilinx ZCU102 комплект для разработки на SoC.
Deep Learning HDL Toolbox™
Пакет поддержки Deep Learning HDL Toolbox™ для Xilinx FPGA и SoC
Deep Learning Toolbox™
Для загрузки предварительно обученной последовательной сети, которая была обучена базе данных Модифицированного национального института стандартов технологии (MNIST), введите:
snet = getDigitsNetwork();
Чтобы просмотреть слои предварительно обученной последовательной сети, введите:
analyzeNetwork(snet)
Создайте целевой объект, который имеет пользовательское имя для вашего целевого устройства и интерфейс для подключения вашего целевого устройства к хосту-компьютеру. Опции интерфейса JTAG и Ethernet.
hTarget = dlhdl.Target('Xilinx','Interface','Ethernet')
hTarget =
Target with properties:
Vendor: 'Xilinx'
Interface: Ethernet
IPAddress: '192.168.1.101'
Username: 'root'
Port: 22
Создайте объект dlhdl.Workflow класс. Задайте сеть и имя битового потока во время создания объекта. Укажите сохраненную предварительно обученную нейронную сеть MNIST, snet, в качестве сети. Убедитесь, что имя битового потока соответствует типу данных и плате FPGA, на которую вы нацелены. В этом примере целевой платой FPGA является плата Xilinx ZCU102 SOC, а в битовом потоке используется один тип данных.
hW = dlhdl.Workflow('network', snet, 'Bitstream', 'zcu102_single','Target',hTarget)
hW =
Workflow with properties:
Network: [1×1 SeriesNetwork]
Bitstream: 'zcu102_single'
ProcessorConfig: []
Target: [1×1 dlhdl.Target]
Чтобы скомпилировать сеть серии MNIST, запустите функцию компиляции dlhdl.Workflow объект.
dn = hW.compile;
### Compiling network for Deep Learning FPGA prototyping ...
### Targeting FPGA bitstream zcu102_single ...
### The network includes the following layers:
1 'imageinput' Image Input 28×28×1 images with 'zerocenter' normalization (SW Layer)
2 'conv_1' Convolution 8 3×3×1 convolutions with stride [1 1] and padding 'same' (HW Layer)
3 'batchnorm_1' Batch Normalization Batch normalization with 8 channels (HW Layer)
4 'relu_1' ReLU ReLU (HW Layer)
5 'maxpool_1' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
6 'conv_2' Convolution 16 3×3×8 convolutions with stride [1 1] and padding 'same' (HW Layer)
7 'batchnorm_2' Batch Normalization Batch normalization with 16 channels (HW Layer)
8 'relu_2' ReLU ReLU (HW Layer)
9 'maxpool_2' Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] (HW Layer)
10 'conv_3' Convolution 32 3×3×16 convolutions with stride [1 1] and padding 'same' (HW Layer)
11 'batchnorm_3' Batch Normalization Batch normalization with 32 channels (HW Layer)
12 'relu_3' ReLU ReLU (HW Layer)
13 'fc' Fully Connected 10 fully connected layer (HW Layer)
14 'softmax' Softmax softmax (SW Layer)
15 'classoutput' Classification Output crossentropyex with '0' and 9 other classes (SW Layer)
3 Memory Regions created.
Skipping: imageinput
Compiling leg: conv_1>>relu_3 ...
### Optimizing series network: Fused 'nnet.cnn.layer.BatchNormalizationLayer' into 'nnet.cnn.layer.Convolution2DLayer'
### Notice: (Layer 1) The layer 'data' with type 'nnet.cnn.layer.ImageInputLayer' is implemented in software.
### Notice: (Layer 10) The layer 'output' with type 'nnet.cnn.layer.RegressionOutputLayer' is implemented in software.
Compiling leg: conv_1>>relu_3 ... complete.
Compiling leg: fc ...
### Notice: (Layer 1) The layer 'data' with type 'nnet.cnn.layer.ImageInputLayer' is implemented in software.
### Notice: (Layer 3) The layer 'output' with type 'nnet.cnn.layer.RegressionOutputLayer' is implemented in software.
Compiling leg: fc ... 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" "4.0 MB"
"OutputResultOffset" "0x00400000" "4.0 MB"
"SchedulerDataOffset" "0x00800000" "4.0 MB"
"SystemBufferOffset" "0x00c00000" "28.0 MB"
"InstructionDataOffset" "0x02800000" "4.0 MB"
"ConvWeightDataOffset" "0x02c00000" "4.0 MB"
"FCWeightDataOffset" "0x03000000" "4.0 MB"
"EndOffset" "0x03400000" "Total: 52.0 MB"
### Network compilation complete.
Чтобы развернуть сеть на оборудовании 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 30-Dec-2020 15:13:03 ### Loading weights to FC Processor. ### FC Weights loaded. Current time is 30-Dec-2020 15:13:03
Чтобы загрузить изображение примера, выполните функцию предсказания dlhdl.Workflow объект, а затем отобразить результат FPGA, введите:
inputImg = imread('five_28x28.pgm');
imshow(inputImg);
Запустите предсказание с профилем ' on ', чтобы увидеть результаты задержки и пропускной способности.
[prediction, speed] = hW.predict(single(inputImg),'Profile','on');
### Finished writing input activations.
### Running single input activations.
Deep Learning Processor Profiler Performance Results
LastFrameLatency(cycles) LastFrameLatency(seconds) FramesNum Total Latency Frames/s
------------- ------------- --------- --------- ---------
Network 98117 0.00045 1 98117 2242.2
conv_1 6607 0.00003
maxpool_1 4716 0.00002
conv_2 4637 0.00002
maxpool_2 2977 0.00001
conv_3 6752 0.00003
fc 72428 0.00033
* The clock frequency of the DL processor is: 220MHz
[val, idx] = max(prediction);
fprintf('The prediction result is %d\n', idx-1);The prediction result is 5