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 ??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 ?? 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 ?? zedboard, fpga, bitstream, neural network, alexnet MATLAB Answers — New Questions