Open juacamgo opened 3 years ago
Brief look at the code seems to show you're not using darknet, but instead the OpenCV dnn implementation. We have no idea how that is implemented, you'd have to ask the OpenCV folks. But considering how the python interface calls the C++ interface under the covers, it is impossible that the python side is faster. If you find that is the case, then there must be something different about the calls you're making in C++. But again, you'd have to ask the OpenCV folks.
Hello @stephanecharette , first of all thank you for the answer.
As pointed in my edit, I've found that using 64 bit compiled OpenCV "solves" the problem, and the C++ code is faster than the Python code.
Found this, I've asked to OpenCV about the issue of performance missmatch between 32-64 bits.
Can I ask you about 2) and 3) questions?
I will now try the Darknet implementation. Thank you!
Hi @juacamgo
I assume that you are new to ML, so I apologize if my answer is « too obvious »
You can modify the network to be both faster and accurate. It depends on the desired detection. If you create your own config file using the advices in the readme.md file for an easy task, the result could lead to a performance drop. A « bigger » dnn isn’t always better. Detecting barcode in a constrained environment looks like an easy task. Maybe you could remove some filters or reduce the input to 320x320.
It’s hard to give you advices without your .cfg file, some examples of the desired output and the graph of your training.
Hi @DylanStouls
Yes, I am new to ML and I am exploring this world for the first time, so any tip or advice will be welcome!
When you said "the resuld could lead to a performance drop" did you mean that I can improve speed sacrificing some accuracy, sure?
Reducing the input to 320x320 I am able to improve speed from 28-32fps to 45 fps. Also, I thought that removing some convolutional filters I could improve the speed, but when I modify the cfg file I need to train again, sure?
I've attached my .cfg file. I will read carefully the readme.md and modify my .cfg file and test performance and accuracy.
Many thanks!
When you said "the resuld could lead to a performance drop" did you mean that I can improve speed sacrificing some accuracy, sure?
I mean that depending on the use case, using a bigger neural network could make your solution less accurate and slower. This phenomenon is called "overfitting". You can find a lot of informations about it online.
Reducing the input to 320x320 I am able to improve speed from 28-32fps to 45 fps. Also, I thought that removing some convolutional filters I could improve the speed, but when I modify the cfg file I need to train again, sure?
You are right, you will have to train again after removing convolutional filters.
I've attached my .cfg file. I will read carefully the readme.md and modify my .cfg file and test performance and accuracy.
There are many tips and explanations in the readme.md. For example, it's written that the max_batches parameters shouldn't be less than 6000.
Moreover, sometimes, it's not necessary to have RGB images. By changing the channel parameter to 1, you can train a greyscale DNN. Generally, we use less filters in a greyscale DNN and in some cases, it could lead to a better accuracy. For a barcode detector, I think that it's worth the try.
Hi @DylanStouls
Thank you for your clear explanations!
I've played a bit with the net, erased some convolutional filters and trained for 320x320 using 1 channel (for greyscale) and now the speed is about 60 fps.
For my surprise, as you said, now the mAP seems to be higher than before with a bigger net, and the net keeps detecting the barcodes very precise.
I will try now to compile for 32 bits arm systems and try on the embedded device to check performance.
Thank you very much!
Hello all,
First of all, want to thanks @AlexeyAB for the great work done here.
I am starting with ML models, and after a bit of research I've ended up training a YOLO-v4 tiny using the roboflow guide, and implemented code on Python and C++ to test inference.
I am planning to use the net to detect the position of a barcode on an image using CPU (so my ML model just needs a class, and I am wondering if even the tiny version of the YOLOv4 net is bigger than my needs).
The CPU my embedded system has is an IMX 6 Quad Processor @1GHz.
After having trained my model, I've implemented some code on Python (for first inference testing on Windows) and I've got about 23 fps. I thought that implementing the same code on C++ will boost a bit the inference, but it just happened the other way round.
With the C++ implementation I am capable of run inference at about 8-9 fps, using the same input size (416x416), while using Python I got around 23-24 fps.
So, here are my questions:
And the code implemented for Python:
C++:
IMPORTANT EDIT: for the testing I was using OpenCV 32 bit compiled (because the final embedded system uses 32 bit), I've tried compile OpenCV for 64 bit and now inference goes from 11 fps (using 32 bit) to 32 fps (using 64 bits), that is about 7-8 fps more than the Python version. I will research a bit about that performance issue.