JeVoisBase  1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Yolo Class Reference

Detect multiple objects in scenes using the Darknet YOLO deep neural network. More...

#include <jevoisbase/Components/ObjectDetection/Yolo.H>

Inheritance diagram for Yolo:
Collaboration diagram for Yolo:

Public Member Functions

 Yolo (std::string const &instance)
 Constructor. More...
 
void postInit () override
 Initialize, configure and load the network in a thread. More...
 
virtual ~Yolo ()
 Virtual destructor for safe inheritance. More...
 
void postUninit () override
 Un-initialize and free resources. More...
 
float predict (cv::Mat const &cvimg)
 Processing function, results are stored internally in the underlying Darknet network object. More...
 
float predict (image &im)
 Processing function, results are stored internally in the underlying Darknet network object. More...
 
void computeBoxes (int inw, int inh)
 Compute the boxes. More...
 
void drawDetections (jevois::RawImage &outimg, int inw, int inh, int xoff, int yoff)
 Draw the detections. More...
 
void sendSerial (jevois::StdModule *mod, int inw, int inh)
 Send serial messages about detections. More...
 
void resizeInDims (int w, int h)
 Resize the network's input image dims. More...
 
void getInDims (int &w, int &h, int &c) const
 Get input width, height, channels. More...
 
- 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
 
Engineengine () const
 
bool initialized () const
 
const std::string & className () const
 
const std::string & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor)
 
void unFreezeParam (std::string const &paramdescriptor)
 
void freezeAllParams ()
 
void unFreezeAllParams ()
 
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)
 
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
 
Engineengine () const
 
bool initialized () const
 
const std::string & className () const
 
const std::string & instanceName () const
 
std::vector< std::string > setParamVal (std::string const &paramdescriptor, T const &val)
 
void setParamValUnique (std::string const &paramdescriptor, T const &val)
 
std::vector< std::pair< std::string, T > > getParamVal (std::string const &paramdescriptor) const
 
getParamValUnique (std::string const &paramdescriptor) const
 
std::vector< std::string > setParamString (std::string const &paramdescriptor, std::string const &val)
 
void setParamStringUnique (std::string const &paramdescriptor, std::string const &val)
 
std::vector< std::pair< std::string, std::string > > getParamString (std::string const &paramdescriptor) const
 
std::string getParamStringUnique (std::string const &paramdescriptor) const
 
void freezeParam (std::string const &paramdescriptor)
 
void unFreezeParam (std::string const &paramdescriptor)
 
void freezeAllParams ()
 
void unFreezeAllParams ()
 
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)
 
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 Functions

(Note that these are not member functions.)

 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. More...
 
 JEVOIS_DECLARE_PARAMETER (datacfg, std::string, "Data configuration file (if relative, relative to dataroot)", "cfg/coco.data", ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (cfgfile, std::string, "Network configuration file (if relative, relative to dataroot)", "cfg/yolov3-tiny.cfg", ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (weightfile, std::string, "Network weights file (if relative, relative to dataroot)", "weights/yolov3-tiny.weights", ParamCateg)
 Parameter. More...
 
 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. More...
 
 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. More...
 
 JEVOIS_DECLARE_PARAMETER (thresh, float, "Detection threshold in percent confidence", 24.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (hierthresh, float, "Hierarchical detection threshold in percent confidence", 50.0F, jevois::Range< float >(0.0F, 100.0F), ParamCateg)
 Parameter. More...
 
 JEVOIS_DECLARE_PARAMETER (threads, int, "Number of parallel computation threads", 6, jevois::Range< int >(1, 1024), ParamCateg)
 Parameter. More...
 

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 ()
 

Detailed Description

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.

Definition at line 89 of file Yolo.H.

Constructor & Destructor Documentation

◆ Yolo()

Yolo::Yolo ( std::string const &  instance)

Constructor.

Definition at line 28 of file Yolo.C.

◆ ~Yolo()

Yolo::~Yolo ( )
virtual

Virtual destructor for safe inheritance.

Definition at line 38 of file Yolo.C.

Member Function Documentation

◆ computeBoxes()

void Yolo::computeBoxes ( int  inw,
int  inh 
)

Compute the boxes.

You must have called predict() first for this to not violently crash.

Definition at line 168 of file Yolo.C.

References dets, map, nboxes, and net.

◆ drawDetections()

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, names, nboxes, jevois::sformat(), and jevois::rawimage::writeText().

Referenced by PythonObject6D.PythonObject6D::process(), and FirstPython.FirstPython::process().

◆ getInDims()

void Yolo::getInDims ( int &  w,
int &  h,
int &  c 
) const

Get input width, height, channels.

Throws std::logic_error if the network is still loading and not ready.

Definition at line 265 of file Yolo.C.

References h, itsReady, net, and demo::w.

◆ postInit()

void Yolo::postInit ( )
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.

◆ postUninit()

void Yolo::postUninit ( )
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.

◆ predict() [1/2]

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 demo::float, h, demo::image, itsReady, LFATAL, and demo::w.

◆ predict() [2/2]

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 demo::image, and net.

◆ resizeInDims()

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.

Definition at line 258 of file Yolo.C.

References h, itsReady, net, and demo::w.

◆ sendSerial()

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().

Friends And Related Function Documentation

◆ JEVOIS_DECLARE_PARAMETER() [1/9]

JEVOIS_DECLARE_PARAMETER ( cfgfile  ,
std::string  ,
"Network configuration file (if relative, relative to dataroot)"  ,
"cfg/yolov3-tiny.cfg"  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [2/9]

JEVOIS_DECLARE_PARAMETER ( datacfg  ,
std::string  ,
"Data configuration file (if relative, relative to dataroot)"  ,
"cfg/coco.data"  ,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [3/9]

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   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [4/9]

JEVOIS_DECLARE_PARAMETER ( hierthresh  ,
float  ,
"Hierarchical detection threshold in percent confidence"  ,
50.  0F,
jevois::Range< float >  0.0F, 100.0F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [5/9]

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   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [6/9]

JEVOIS_DECLARE_PARAMETER ( nms  ,
float  ,
"Non-maximum suppression intersection-over-union threshold in percent"  ,
45.  0F,
jevois::Range< float >  0.0F, 100.0F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [7/9]

JEVOIS_DECLARE_PARAMETER ( threads  ,
int  ,
"Number of parallel computation threads"  ,
,
jevois::Range< int >  1, 1024,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [8/9]

JEVOIS_DECLARE_PARAMETER ( thresh  ,
float  ,
"Detection threshold in percent confidence"  ,
24.  0F,
jevois::Range< float >  0.0F, 100.0F,
ParamCateg   
)
related

Parameter.

◆ JEVOIS_DECLARE_PARAMETER() [9/9]

JEVOIS_DECLARE_PARAMETER ( weightfile  ,
std::string  ,
"Network weights file (if relative, relative to dataroot)"  ,
"weights/yolov3-tiny.weights"  ,
ParamCateg   
)
related

Parameter.

Member Data Documentation

◆ classes

◆ dets

detection* Yolo::dets

Definition at line 148 of file Yolo.H.

Referenced by computeBoxes(), drawDetections(), postUninit(), and sendSerial().

◆ itsReady

std::atomic<bool> Yolo::itsReady
protected

Definition at line 154 of file Yolo.H.

Referenced by getInDims(), postInit(), predict(), and resizeInDims().

◆ itsReadyFut

std::future<void> Yolo::itsReadyFut
protected

Definition at line 153 of file Yolo.H.

Referenced by postInit(), and postUninit().

◆ map

int* Yolo::map

Definition at line 150 of file Yolo.H.

Referenced by computeBoxes(), postInit(), and postUninit().

◆ names

char** Yolo::names

Definition at line 146 of file Yolo.H.

Referenced by drawDetections(), postInit(), postUninit(), and sendSerial().

◆ nboxes

int Yolo::nboxes

Definition at line 147 of file Yolo.H.

Referenced by computeBoxes(), drawDetections(), postUninit(), and sendSerial().

◆ net


The documentation for this class was generated from the following files: