JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Identify an object using Darknet deep neural network. More...
#include <jevoisbase/Components/ObjectDetection/Darknet.H>
Public Member Functions | |
Darknet (std::string const &instance, bool show_detail_params=false) | |
Constructor. | |
void | postInit () override |
Initialize, configure and load the network in a thread. | |
virtual | ~Darknet () |
Virtual destructor for safe inheritance. | |
void | postUninit () override |
Un-initialize and free resources. | |
float | predict (cv::Mat const &cvimg, std::vector< jevois::ObjReco > &results) |
Processing function, results are stored internally in the underlying Darknet network object. | |
float | predict (image &im, std::vector< jevois::ObjReco > &results) |
Processing function, results are stored internally in the underlying Darknet network object. | |
void | resizeInDims (int w, int h) |
Resize the network's input image dims. | |
void | getInDims (int &w, int &h, int &c) |
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 = nullptr |
int | classes |
Protected Member Functions | |
void | onParamChange (dknet::netw const ¶m, dknet::Net const &newval) override |
void | onParamChange (dknet::dataroot const ¶m, std::string const &newval) override |
void | onParamChange (dknet::datacfg const ¶m, std::string const &newval) override |
void | onParamChange (dknet::cfgfile const ¶m, std::string const &newval) override |
void | onParamChange (dknet::weightfile const ¶m, std::string const &newval) override |
void | onParamChange (dknet::namefile const ¶m, std::string const &newval) override |
void | loadNet () |
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 () |
Protected Attributes | |
std::future< void > | itsReadyFut |
std::atomic< bool > | itsReady |
bool const | itsShowDetailParams |
std::atomic< bool > | itsNeedReload |
Related Symbols | |
(Note that these are not member symbols.) | |
JEVOIS_DEFINE_ENUM_CLASS (Net,(Reference)(Tiny)) | |
Enum. | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (netw, Net, "Network to load. This meta-parameter sets parameters " "dataroot, datacfg, cfgfile, weightfile, and namefile for the chosen network.", Net::Tiny, Net_Values, ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (dataroot, std::string, "Root path for data, config, and weight files. " "If empty, use the module's path.", JEVOIS_SHARE_PATH "/darknet/single", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (datacfg, std::string, "Data configuration file (if relative, relative to " "dataroot)", "cfg/imagenet1k.data", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (cfgfile, std::string, "Network configuration file (if relative, relative to " "dataroot)", "cfg/tiny.cfg", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (weightfile, std::string, "Network weights file (if relative, relative to " "dataroot)", "weights/tiny.weights", ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (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 (top, unsigned int, "Max number of top-scoring predictions that score above thresh to return", 5, ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (thresh, float, "Threshold (in percent confidence) above which predictions will be reported", 20.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. | |
Identify an object using Darknet deep neural network.
Darknet is a popular neural network framework. This component identifies the object in the given image crop. It returns the top scoring candidates.
See https://pjreddie.com/darknet
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.
Darknet::Darknet | ( | std::string const & | instance, |
bool | show_detail_params = false |
||
) |
Constructor.
if show_detail_params is false, the parameters dataroot, datacfg, cfgfile, weightfile, and namefile are hidden and users can just use the parameter network to set various predefined networks.
Definition at line 28 of file Darknet.C.
References itsShowDetailParams.
|
virtual |
Virtual destructor for safe inheritance.
Definition at line 49 of file Darknet.C.
References itsReadyFut, and JEVOIS_WAIT_GET_FUTURE.
void Darknet::getInDims | ( | int & | w, |
int & | h, | ||
int & | c | ||
) |
|
protected |
Definition at line 115 of file Darknet.C.
References jevois::Component::absolutePath(), jevois::async(), classes, itsNeedReload, itsReady, itsReadyFut, LFATAL, LINFO, names, and net.
Referenced by getInDims(), postInit(), predict(), predict(), and resizeInDims().
|
overrideprotected |
Definition at line 103 of file Darknet.C.
References itsNeedReload.
|
overrideprotected |
Definition at line 102 of file Darknet.C.
References itsNeedReload.
|
overrideprotected |
Definition at line 101 of file Darknet.C.
References itsNeedReload.
|
overrideprotected |
Definition at line 105 of file Darknet.C.
References itsNeedReload.
|
overrideprotected |
Definition at line 60 of file Darknet.C.
References itsShowDetailParams, and JEVOIS_SHARE_PATH.
|
overrideprotected |
Definition at line 104 of file Darknet.C.
References itsNeedReload.
|
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 108 of file Darknet.C.
References loadNet().
|
overridevirtual |
Un-initialize and free resources.
Reimplemented from jevois::Component.
Definition at line 184 of file Darknet.C.
References classes, itsReadyFut, names, and net.
float Darknet::predict | ( | cv::Mat const & | cvimg, |
std::vector< jevois::ObjReco > & | results | ||
) |
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. If the image dims do not match the network's input layer dims, we here resize the network (beware that this only works if the network is fully convolutional). 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 202 of file Darknet.C.
References h, itsNeedReload, itsReady, LFATAL, loadNet(), and predict().
Referenced by predict().
float Darknet::predict | ( | image & | im, |
std::vector< jevois::ObjReco > & | results | ||
) |
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]. If the image dims do not match the network's input layer dims, we here resize the network (beware that this only works if the network is fully convolutional). 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 229 of file Darknet.C.
References itsNeedReload, itsReady, loadNet(), names, and net.
void Darknet::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 266 of file Darknet.C.
References h, itsNeedReload, itsReady, loadNet(), and net.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Enum.
int Darknet::classes |
Definition at line 144 of file Darknet.H.
Referenced by PyPostClassify.PyPostClassify::freeze(), PyPostDAMOyolo.PyPostDAMOyolo::freeze(), PyPostYolo.PyPostYolo::freeze(), PyPostYOLOv8seg.PyPostYOLOv8seg::freeze(), loadNet(), PyDetectionDNN.PyDetectionDNN::postprocess(), postUninit(), and PyClassificationDNN.PyClassificationDNN::process().
|
protected |
Definition at line 158 of file Darknet.H.
Referenced by getInDims(), loadNet(), onParamChange(), onParamChange(), onParamChange(), onParamChange(), onParamChange(), predict(), predict(), and resizeInDims().
|
protected |
Definition at line 156 of file Darknet.H.
Referenced by getInDims(), loadNet(), predict(), predict(), and resizeInDims().
|
protected |
Definition at line 155 of file Darknet.H.
Referenced by loadNet(), postUninit(), and ~Darknet().
|
protected |
Definition at line 157 of file Darknet.H.
Referenced by Darknet(), and onParamChange().
char** Darknet::names = nullptr |
Definition at line 143 of file Darknet.H.
Referenced by loadNet(), postUninit(), and predict().
network* Darknet::net |
Definition at line 142 of file Darknet.H.
Referenced by getInDims(), PyNetKSNN.PyNetKSNN::load(), PyNetOpenCV.PyNetOpenCV::load(), loadNet(), PyDetectionDNN.PyDetectionDNN::postprocess(), postUninit(), predict(), PyNetKSNN.PyNetKSNN::process(), PyNetOpenCV.PyNetOpenCV::process(), PyClassificationDNN.PyClassificationDNN::process(), PyDetectionDNN.PyDetectionDNN::process(), and resizeInDims().