Problem with Deploying YOLO 2 to Raspberry

4 views (last 30 days)
Abdussalam Elhanashi
Abdussalam Elhanashi on 18 Feb 2020
Answered: Puru Kathuria on 25 Feb 2021
Hi guys
I am doing deployment of yolo 2 to raspi however i am recieving the problem. i think it is with the camera (w) and herein the the following error :-
>> Untitled3
Deploying code. This may take a few minutes.
??? Variable 'w' is not fully defined on some execution paths.
Error in ==> detectobjectvideostreamliveviaraspi Line: 13 Column: 17
Code generation failed: View Error Report
Error using codegen
Error in Untitled3 (line 33)
codegen('-config ', cfg,'detectobjectvideostreamliveviaraspi', '-report');
Here in the function that i am calling:-
function detectobjectvideostreamliveviaraspi()
%#codegen
persistent yolov2Obj;
if isempty(yolov2Obj)
yolov2Obj = coder.loadDeepLearningNetwork('detectorYolo2.mat');
hwobj = raspi;
w = webcam(hwobj);
end
for i = 1:1800
img = snapshot(w);
img=imresize(img,[640,480]);
fps = 0;
avgfps = [];
tic;
[bboxes,scores] = detect(yolov2Obj,img,'Threshold',0.4);
newt = toc;
% fps
fps = .9*fps + .1*(1/newt);
avgfps = [avgfps, fps]; %#ok<AGROW>
if ~isempty(bboxes)
I = insertObjectAnnotation(img,'rectangle',bboxes,scores);
else
I = img;
end
I = insertText(I , [1, 1], sprintf('FPS %2.2f', fps), 'FontSize', 26);
displayImage(hwobj,I,'Title','detectedImg');
end
and herein the deployment code to raspi
%Create a C++ code generation configuration object.
cfg = coder.config('exe');
cfg.TargetLang = 'C++';
%Specify Use of the ARM Compute Library. The ARM Compute Library provides optimized functionality for the Raspberry Pi hardware. To generate code that uses the ARM Compute Library, create a coder.ARMNEONConfig object. Specify the version of the ARM Compute Library installed on your Raspberry Pi and the architecture of the Raspberry Pi. Attach the deep learning configuration cbject to the code generation configuration object
dlcfg = coder.DeepLearningConfig('arm-compute');
supportedVersions = dlcfg.getARMComputeSupportedVersions;
dlcfg.ArmArchitecture = 'armv7';
dlcfg.ArmComputeVersion = '19.02';
cfg.DeepLearningConfig = dlcfg;
%Create a Connection to the Raspberry Pi
hwobj = raspi;
%Configure Code Generation Hardware Parameters for Raspberry Pi
hw = coder.hardware('Raspberry Pi');
cfg.Hardware = hw;
%Specify a build folder on the Raspberry Pi:
buildDir = '~/remoteBuildDir';
cfg.Hardware.BuildDir = buildDir;
%Provide a C++ Main File
CustomInclude=fullfile('codgen','exe','detectobjectvideostreamliveviaraspi','example');
cfg.CustomSource =fullfile('codgen','exe', 'detectobjectvideostreamliveviaraspi','example','main cu');
yolov2Obj = coder.loadDeepLearningNetwork('detectorYolo2.mat');
%Generate the Executable Program on the Raspberry Pi
codegen('-config ', cfg,'detectobjectvideostreamliveviaraspi', '-report');
kindly looking for support
Best,

Answers (1)

Puru Kathuria
Puru Kathuria on 25 Feb 2021
The error states that there is a possible execution path where w is not defined. The call to webcam function might lead to an instance where w remains undefined.
To resolve this, you can try defining w with default values before calling webcam.So that for all the execution paths, w has a defined value.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by