How to generate Custom Bitstream for Zedboard to deploy Neural Network model?

imds = imageDatastore('Result_fish_images(NA)', ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
%%
[imdsTrain,imdsValidation,imdsTest] = splitEachLabel(imds,0.7,0.15,0.15,"randomized");
%%
numTrainImages = numel(imdsTrain.Labels);
idx = randperm(numTrainImages,16);
figure
for i = 1:16
subplot(4,4,i)
I = readimage(imdsTrain,idx(i));
imshow(I)
end
%%
classNames = categories(imdsTrain.Labels);
numClasses = numel(classNames)
%%
net = imagePretrainedNetwork("alexnet",NumClasses=numClasses);
net = setLearnRateFactor(net,"fc8/Weights",20);
net = setLearnRateFactor(net,"fc8/Bias",20);
%%
inputSize = net.Layers(1).InputSize
%%
pixelRange = [-30 30];
imageAugmenter = imageDataAugmenter( ...
'RandXReflection',true, ...
'RandXTranslation',pixelRange, ...
'RandYTranslation',pixelRange);
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain, ...
'DataAugmentation',imageAugmenter);
%%
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation);
%%
options = trainingOptions("sgdm", ...
MiniBatchSize=10, ...
MaxEpochs=6, ...
Metrics="accuracy", ...
InitialLearnRate=1e-4, ...
Shuffle="every-epoch", ...
ValidationData=augimdsValidation, ...
ValidationFrequency=3, ...
Verbose=false, ...
Plots="training-progress");
%%
net = trainnet(augimdsTrain,net,"crossentropy",options);
%%
scores = minibatchpredict(net,augimdsValidation);
YPred = scores2label(scores,classNames);
%%
idx = randperm(numel(imdsValidation.Files),4);
figure
for i = 1:4
subplot(2,2,i)
I = readimage(imdsValidation,idx(i));
imshow(I)
label = YPred(idx(i));
title(string(label));
end
%%
YValidation = imdsValidation.Labels;
accuracy = mean(YPred == YValidation)
%%After the above we performed the quantization and saved the network in quantizedNet variable. We flashed the %%memory card with linux image for zedboard using SoC Blockset support package. We tested the communication between %%our zedboard and laptop via zynq() command and were able to retreive the IP Address of it. Now we want to deploy the %%trained model on zedboard platform using:
%%hTarget = dlhdl.Target('Xilinx','Interface','Ethernet');
%%hW = dlhdl.Workflow('Network',quantizedNet,'Bitstream','zcu102_int8','Target',hTarget);
%%dn=hW.compile;
%%hW.deploy;
%%output=hW.predict(InputImg);
%%This should give us prediction result by performing the operation on FPGA and fetching back the result.
%%But here the pre built bit streams like zc0102 or zc706 are not available for zedboard. How to generate custom %%bitstream targetting zedboard ??

Answers (1)

Hi,
To generate custom bitstream for your target please refer to the documentation below which illustrates on how to configure custom bitstream using “dlhdl.ProcessorConfig;” object :
Additionally, here is an example for deploying on an FPGA, specifically the Xilinx ZC706 SoC, with bitstream customization:

1 Comment

Hey thanks for replying.
We have trained the AlexNet for underwater images already and we want to deploy it on Zedboard (or Zc702 if possible because we have only these 2 boards in our university labs). We tried generating custom bitstream for it using below commands:
%%
hPC = dlhdl.ProcessorConfig;
%%
hdlsetuptoolpath('ToolName','Xilinx Vivado','ToolPath','D:\Vivado\2023.1\bin\vivado.bat');
%%
dlhdl.buildProcessor(hPC);
It runs till the end and tells that Workflow is complete but it doesnt generate bitstream file like in this below link:
dlprocessor.bit isnt being generated. Rest all files are created.
Any other method we can try getting the bit file for trained neural network model in matlab??

Sign in to comment.

Categories

Asked:

on 29 Jul 2024

Commented:

on 8 Aug 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!