JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Detect multiple objects in scenes using the Darknet YOLO deep neural network. More...
#include <jevoisbase/Components/ObjectDetection/Yolo.H>
Public Member Functions | |
Yolo (std::string const &instance) | |
Constructor. | |
void | postInit () override |
Initialize, configure and load the network in a thread. | |
virtual | ~Yolo () |
Virtual destructor for safe inheritance. | |
void | postUninit () override |
Un-initialize and free resources. | |
float | predict (cv::Mat const &cvimg) |
Processing function, results are stored internally in the underlying Darknet network object. | |
float | predict (image &im) |
Processing function, results are stored internally in the underlying Darknet network object. | |
void | computeBoxes (int inw, int inh) |
Compute the boxes. | |
void | drawDetections (jevois::RawImage &outimg, int inw, int inh, int xoff, int yoff) |
Draw the detections. | |
void | sendSerial (jevois::StdModule *mod, int inw, int inh) |
Send serial messages about detections. | |
void | resizeInDims (int w, int h) |
Resize the network's input image dims. | |
void | getInDims (int &w, int &h, int &c) const |
Get input width, height, channels. | |
Public Member Functions inherited from jevois::Component | |
Component (std::string const &instance) | |
virtual | ~Component () |
std::shared_ptr< Comp > | addSubComponent (std::string const &instance, Args &&...args) |
void | removeSubComponent (std::shared_ptr< Comp > &component) |
void | removeSubComponent (std::string const &instance, bool warnIfNotFound=true) |
std::shared_ptr< Comp > | getSubComponent (std::string const &instance) const |
bool | isTopLevel () const |
bool | initialized () const |
std::string const & | className () const |
std::string const & | instanceName () const |
std::vector< std::string > | setParamVal (std::string const ¶mdescriptor, T const &val) |
void | setParamValUnique (std::string const ¶mdescriptor, T const &val) |
std::vector< std::pair< std::string, T > > | getParamVal (std::string const ¶mdescriptor) const |
T | getParamValUnique (std::string const ¶mdescriptor) const |
std::vector< std::string > | setParamString (std::string const ¶mdescriptor, std::string const &val) |
void | setParamStringUnique (std::string const ¶mdescriptor, std::string const &val) |
std::vector< std::pair< std::string, std::string > > | getParamString (std::string const ¶mdescriptor) const |
std::string | getParamStringUnique (std::string const ¶mdescriptor) const |
void | freezeParam (std::string const ¶mdescriptor, bool doit) |
void | freezeAllParams (bool doit) |
std::string | descriptor () const |
void | setParamsFromFile (std::string const &filename) |
std::istream & | setParamsFromStream (std::istream &is, std::string const &absfile) |
virtual void | paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="") |
void | foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="") |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category) |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category) |
void | setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true) |
void | removeDynamicParameter (std::string const &name, bool throw_if_not_found=true) |
void | setPath (std::string const &path) |
std::filesystem::path | absolutePath (std::filesystem::path const &path="") |
std::shared_ptr< Comp > | addSubComponent (std::string const &instance, Args &&...args) |
void | removeSubComponent (std::shared_ptr< Comp > &component) |
void | removeSubComponent (std::string const &instance, bool warnIfNotFound=true) |
std::shared_ptr< Comp > | getSubComponent (std::string const &instance) const |
bool | isTopLevel () const |
bool | initialized () const |
std::string const & | className () const |
std::string const & | instanceName () const |
std::vector< std::string > | setParamVal (std::string const ¶mdescriptor, T const &val) |
void | setParamValUnique (std::string const ¶mdescriptor, T const &val) |
std::vector< std::pair< std::string, T > > | getParamVal (std::string const ¶mdescriptor) const |
T | getParamValUnique (std::string const ¶mdescriptor) const |
std::vector< std::string > | setParamString (std::string const ¶mdescriptor, std::string const &val) |
void | setParamStringUnique (std::string const ¶mdescriptor, std::string const &val) |
std::vector< std::pair< std::string, std::string > > | getParamString (std::string const ¶mdescriptor) const |
std::string | getParamStringUnique (std::string const ¶mdescriptor) const |
void | freezeParam (std::string const ¶mdescriptor, bool doit) |
void | freezeAllParams (bool doit) |
std::string | descriptor () const |
void | setParamsFromFile (std::string const &filename) |
std::istream & | setParamsFromStream (std::istream &is, std::string const &absfile) |
virtual void | paramInfo (std::shared_ptr< UserInterface > s, std::map< std::string, std::string > &categs, bool skipFrozen, std::string const &cname="", std::string const &pfx="") |
void | foreachParam (std::function< void(std::string const &compname, ParameterBase *p)> func, std::string const &cname="") |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ParameterCategory const &category) |
std::shared_ptr< DynamicParameter< T > > | addDynamicParameter (std::string const &name, std::string const &description, T const &defaultValue, ValidValuesSpec< T > const &validValuesSpec, ParameterCategory const &category) |
void | setDynamicParameterCallback (std::string const &name, std::function< void(T const &)> cb, bool callnow=true) |
void | removeDynamicParameter (std::string const &name, bool throw_if_not_found=true) |
void | setPath (std::string const &path) |
std::filesystem::path | absolutePath (std::filesystem::path const &path="") |
Public Member Functions inherited from jevois::ParameterRegistry | |
virtual | ~ParameterRegistry () |
Public Attributes | |
network * | net |
char ** | names |
int | nboxes |
detection * | dets |
int | classes |
int * | map |
Protected Attributes | |
std::future< void > | itsReadyFut |
std::atomic< bool > | itsReady |
Related Symbols | |
(Note that these are not member symbols.) | |
JEVOIS_DECLARE_PARAMETER (dataroot, std::string, "Root path for data, config, and weight files. If empty, use " "the module's path.", JEVOIS_SHARE_PATH "/darknet/yolo", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (datacfg, std::string, "Data configuration file (if relative, relative to dataroot)", "cfg/coco.data", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (cfgfile, std::string, "Network configuration file (if relative, relative to dataroot)", "cfg/yolov3-tiny.cfg", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (weightfile, std::string, "Network weights file (if relative, relative to dataroot)", "weights/yolov3-tiny.weights", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (namefile, std::string, "Category names file, or empty to fetch it from the network " "config file (if relative, relative to dataroot)", "", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (nms, float, "Non-maximum suppression intersection-over-union threshold in percent", 45.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (thresh, float, "Detection threshold in percent confidence", 24.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (hierthresh, float, "Hierarchical detection threshold in percent confidence", 50.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (threads, int, "Number of parallel computation threads", 6, jevois::Range< int >(1, 1024), ParamCateg) | |
Parameter. | |
Additional Inherited Members | |
Protected Member Functions inherited from jevois::Component | |
virtual void | preInit () |
virtual void | preUninit () |
virtual void | preInit () |
virtual void | preUninit () |
Protected Member Functions inherited from jevois::ParameterRegistry | |
void | addParameter (ParameterBase *const param) |
void | removeParameter (ParameterBase *const param) |
void | callbackInitCall () |
Detect multiple objects in scenes using the Darknet YOLO deep neural network.
Darknet is a popular neural network framework, and YOLO is a very interesting network that detects all objects in a scene in one pass. This component detects all instances of any of the objects it knows about (determined by the network structure, labels, dataset used for training, and weights obtained) in the image that is given to is.
See https://pjreddie.com/darknet/yolo/
Darknet is a great, bare-metal deep learning and deep neural network framework. It is great for embedded systems like the small JeVois camera because it has a very small footprint and fewer dependencies than other deep neural network frameworks like Tensorflow, MXNet, Theano, Keras, PyTorch, etc. In addition, the port of Darknet to JeVois includes acceleration using the ARM NEON multimedia instructions through the popular NNPACK neural network acceleration package.
|
virtual |
void Yolo::computeBoxes | ( | int | inw, |
int | inh | ||
) |
void Yolo::drawDetections | ( | jevois::RawImage & | outimg, |
int | inw, | ||
int | inh, | ||
int | xoff, | ||
int | yoff | ||
) |
Draw the detections.
You must have called computeBoxes() first for this to not violently crash.
Definition at line 182 of file Yolo.C.
References classes, dets, jevois::rawimage::drawRect(), jevois::rawimage::Font10x20, jevois::yuyv::LightGreen, names, nboxes, jevois::sformat(), and jevois::rawimage::writeText().
Referenced by FirstPython.FirstPython::process(), and PythonObject6D.PythonObject6D::process().
void Yolo::getInDims | ( | int & | w, |
int & | h, | ||
int & | c | ||
) | const |
|
overridevirtual |
Initialize, configure and load the network in a thread.
Any call to process() will simply throw until the network is loaded and ready
Reimplemented from jevois::Component.
Definition at line 46 of file Yolo.C.
References jevois::Component::absolutePath(), jevois::async(), classes, itsReady, itsReadyFut, LFATAL, LINFO, map, names, and net.
|
overridevirtual |
Un-initialize and free resources.
Reimplemented from jevois::Component.
Definition at line 98 of file Yolo.C.
References classes, dets, itsReadyFut, map, names, nboxes, and net.
float Yolo::predict | ( | cv::Mat const & | cvimg | ) |
Processing function, results are stored internally in the underlying Darknet network object.
This version expects an OpenCV RGB byte image which will be converted to float RGB planar, and which may be letterboxed if necessary to fit network input dims. Returns the prediction time (neural net forward pass) in milliseconds. Throws std::logic_error if the network is still loading and not ready.
Definition at line 121 of file Yolo.C.
References h, itsReady, LFATAL, and predict().
Referenced by predict().
float Yolo::predict | ( | image & | im | ) |
Processing function, results are stored internally in the underlying Darknet network object.
This version expects a Darknet image input, RGB float planar normalized to [0..1], with same dims as network input dims. Returns the prediction time (neural net forward pass) in milliseconds. Throws std::logic_error if the network is still loading and not ready.
Definition at line 148 of file Yolo.C.
References net.
void Yolo::resizeInDims | ( | int | w, |
int | h | ||
) |
Resize the network's input image dims.
This will prepare the network to receive inputs of the specified size. It is optional and will be called automatically by predict() if the given image size does not match the current network input size. Note that this only works with fully convolutional networks. Note that the number of channels cannot be changed at this time. Throws std::logic_error if the network is still loading and not ready.
void Yolo::sendSerial | ( | jevois::StdModule * | mod, |
int | inw, | ||
int | inh | ||
) |
Send serial messages about detections.
You must have called computeBoxes() first for this to not violently crash. The module given should be the owner of this component, we will use it to actually send each serial message using some variant of jevois::Module::sendSerial().
Definition at line 225 of file Yolo.C.
References classes, dets, names, nboxes, and jevois::StdModule::sendSerialObjDetImg2D().
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
int Yolo::classes |
Definition at line 149 of file Yolo.H.
Referenced by drawDetections(), PyPostClassify.PyPostClassify::freeze(), PyPostDAMOyolo.PyPostDAMOyolo::freeze(), PyPostYolo.PyPostYolo::freeze(), PyPostYOLOv8seg.PyPostYOLOv8seg::freeze(), postInit(), PyDetectionDNN.PyDetectionDNN::postprocess(), postUninit(), PyClassificationDNN.PyClassificationDNN::process(), and sendSerial().
detection* Yolo::dets |
Definition at line 148 of file Yolo.H.
Referenced by computeBoxes(), drawDetections(), postUninit(), and sendSerial().
|
protected |
Definition at line 154 of file Yolo.H.
Referenced by getInDims(), postInit(), predict(), and resizeInDims().
|
protected |
Definition at line 153 of file Yolo.H.
Referenced by postInit(), and postUninit().
int* Yolo::map |
Definition at line 150 of file Yolo.H.
Referenced by computeBoxes(), postInit(), and postUninit().
char** Yolo::names |
Definition at line 146 of file Yolo.H.
Referenced by drawDetections(), postInit(), postUninit(), and sendSerial().
int Yolo::nboxes |
Definition at line 147 of file Yolo.H.
Referenced by computeBoxes(), drawDetections(), postUninit(), and sendSerial().
network* Yolo::net |
Definition at line 145 of file Yolo.H.
Referenced by computeBoxes(), getInDims(), PyNetKSNN.PyNetKSNN::load(), PyNetOpenCV.PyNetOpenCV::load(), postInit(), PyDetectionDNN.PyDetectionDNN::postprocess(), postUninit(), predict(), PyNetKSNN.PyNetKSNN::process(), PyNetOpenCV.PyNetOpenCV::process(), PyClassificationDNN.PyClassificationDNN::process(), PyDetectionDNN.PyDetectionDNN::process(), and resizeInDims().