How to measure frame rate per seconds

Hi

recently I have deployed yolov2 from MATLAB to jetson nano . I am using raspi camera v2 connected to CSI port and gstreamer in jetson nano .unfortunately in MATLAB code , it is not possible to add function for reading frames per second. I would like to find such way when I run deployed code in jeston nano , I want to know how much frame per seconds while deep learning yolov2 running with streaming from raspi camera . Is there any log file or such way to find how much is the frame rate when deployed code was running

Looking for your support

Best

Hi @a.elhanashi, the rate that the camera runs may not be the same that the MATLAB inferencing code runs (for example the rPI camera would likely run at a consistent 30Hz, whereas YOLO model could be less or more than that).

Is there any code after MATLAB that interprets the results (e.g. bounding boxes), that you could add timing when the YOLO results are recieved?

Hi @a.elhanashi,

If it is an alternative for you to use GStreamer, you can use the following project:

It is a gstreamer plugin that can help to measure framerate. It is as simple as adding the perf element to the GStreamer pipeline.

For example:

gst-launch-1.0 -e videotestsrc ! x264enc ! perf ! qtmux print-arm-load=true ! filesink location=test.mp4

Regards,
Fabian
www.ridgerun.com

1 Like

Hi

when I try this code function the deployment processed successfully

function yolo2detectobject()
%#codegen
%Copyright 2019 - 2019 The MathWorks, Inc.
%Load the pre-trained Fire and Smoke detection network
persistent yolov2Obj;
if isempty(yolov2Obj)
yolov2Obj = coder.loadDeepLearningNetwork(‘detectorYolo2.mat’);
end
hwobj = jetson;
w = camera(hwobj,“vi-output, imx219 6-0010”,[1280 720]);
d = imageDisplay(hwobj);
for k = 1:1800
% Capture the image from the webcam on hardware.
I = snapshot(w);
I=imresize(I,[640 480]);

% Run the detector on the input test image
[bboxes, scores, ~] = detect(yolov2Obj, I,'Threshold',0.5);

% Insert bounding box to test image
I = insertObjectAnnotation(I, 'rectangle', bboxes, scores);

% Display output on the target monitor
image(d, I);

end
end

But when I made this code by adding functions for frame per second measurement I got deployment failed

function yolo2detectobject()
%#codegen
%Copyright 2019 - 2019 The MathWorks, Inc.
%Load the pre-trained Fire and Smoke detection network
persistent yolov2Obj;
if isempty(yolov2Obj)
yolov2Obj = coder.loadDeepLearningNetwork(‘detectorYolo2.mat’);
end
hwobj = jetson;
w = camera(hwobj,“vi-output, imx219 6-0010”,[1280 720]);
d = imageDisplay(hwobj);
for k = 1:1800
% Capture the image from the webcam on hardware.
I = snapshot(w);
I=imresize(I,[640 480]);
fps = 0;
avgfps = ;
tic;
% Run the detector on the input test image
[bboxes, scores, ~] = detect(yolov2Obj, I,‘Threshold’,0.5);
newt = toc;
% fps
fps = .9fps + .1(1/newt);
avgfps = [avgfps, fps]; %#ok<NASGU,AGROW>

% Insert bounding box to test image
if isempty(scores) == 0
I = insertObjectAnnotation(I, 'rectangle', bboxes, scores);
I  = insertText(I , [1, 1],  sprintf('FPS %2.2f', fps));     
end
% Display output on the target monitor
I  = insertText(I , [1, 1],  sprintf('FPS %2.2f', fps));     

image(d, I);
I am looking that  when I run this command  and file yolo2detectobject.elf which streaming from raspi camera I want to way how to measure the frame rate 

jetsonnano3@jetsonnano3-desktop:~/remoteBuildTest/MATLAB_ws/R2019b/C/Users/Abdussalam/Desktop/Train_R-CNN_SmokeDetector10$ ./yolo2detectobject.elf

Hi Fabian

How can I implement you suggestion. I am running my deployed file in terminal as the command below
jetsonnano3@jetsonnano3-desktop:~/remoteBuildTest/MATLAB_ws/R2019b/C/Users/Abdussalam/Desktop/Train_R-CNN_SmokeDetector10$ ./yolo2detectobject.elf

once I press enter I got this massage

GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 4
Output Stream W = 1280 H = 720
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: PowerService: requested_clock_Hz=6048000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.

and then starting streaming video from raspi camera

so here with your implementation how can I measure frames per seconds while I am running this in terminal

jetsonnano3@jetsonnano3-desktop:~/remoteBuildTest/MATLAB_ws/R2019b/C/Users/Abdussalam/Desktop/Train_R-CNN_SmokeDetector10$ ./yolo2detectobject.elf

Hi @a.elhanashi,

Good, this output means that you are indeed using GStreamer

You can follow the instructions here: GitHub - RidgeRun/gst-perf: GStreamer element to measure framerate, bitrate and CPU usage. to compile and install the GStreamer plugin.

The in the source code of your program you must find the Gstreamer pipeline that is being used and add the perf element there.

Regards,
Fabian
www.ridgerun.com

Hi Fabian

really I am appreciated for finding the solution and your quick reply

Since I am new in jetson nano and using terminal can I get steps for installing plugin

and once installed where I put pref in my command .Because all iam doing I go to terminal and I use this command to start streaming streaming from video

This command

jetsonnano3@jetsonnano3-desktop:~/remoteBuildTest/MATLAB_ws/R2019b/C/Users/Abdussalam/Desktop/Train_R-CNN_SmokeDetector10$ ./yolo2detectobject.elf

The instructions to install the plugin:

git clone https://github.com/RidgeRun/gst-perf
cd gst-perf
./autogen
./configure
make
sudo make install

Then the perf cannot be added to your command

jetsonnano3@jetsonnano3-desktop:~/remoteBuildTest/MATLAB_ws/R2019b/C/Users/Abdussalam/Desktop/Train_R-CNN_SmokeDetector10$ ./yolo2detectobject.elf

It must be added in the source code of the program where you define the gstreamer pipeline

Regards,
Fabian
www.ridgerun.com

Hi Fabian

That is the issue . Because it is deployed code from MATLAB so the only thing thing I can do in jetson nano is to run it in terminal by mentioned code. It is not neccessry to see fps on video even if the video is finished I want get what was fps by any other commands or log file

Is there any other way to get fps

Best