JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Wrapper around a neural network implemented by with the tiny-dnn framework by Taiga Nomi. More...
#include <jevoisbase/Components/ObjectRecognition/ObjectRecognition.H>
Public Member Functions | |
ObjectRecognition (std::string const &instance) | |
Constructor allocates the (empty) network. | |
virtual | ~ObjectRecognition () |
Destructor. | |
virtual tiny_dnn::index3d< size_t > | insize () const override |
Get the input size for the current network, useful to prepare inputs to process() | |
vec_t | process (cv::Mat const &img, bool normalize=true) override |
Process an image, results are confidence for each category. | |
Public Member Functions inherited from ObjectRecognitionBase | |
ObjectRecognitionBase (std::string const &instance) | |
Constructor. | |
virtual | ~ObjectRecognitionBase () |
Virtual destructor for safe inheritance. | |
virtual void | define ()=0 |
Define the network structure. | |
virtual void | train (std::string const &path)=0 |
Train the network. | |
virtual std::string const & | category (size_t idx) const =0 |
Return the name of a given category (0-based index in the vector of results) | |
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 () |
Protected Member Functions | |
virtual void | postInit () override |
Initialize the network, required before one starts using it. | |
Protected Member Functions inherited from jevois::Component | |
virtual void | preInit () |
virtual void | preUninit () |
virtual void | postUninit () |
virtual void | preInit () |
virtual void | preUninit () |
virtual void | postUninit () |
Protected Member Functions inherited from jevois::ParameterRegistry | |
void | addParameter (ParameterBase *const param) |
void | removeParameter (ParameterBase *const param) |
void | callbackInitCall () |
Protected Attributes | |
tiny_dnn::network< NetType > * | net |
Additional Inherited Members | |
Public Types inherited from ObjectRecognitionBase | |
typedef std::vector< tiny_dnn::float_t, tiny_dnn::aligned_allocator< tiny_dnn::float_t, 64 > > | vec_t |
Type used by tiny-dnn for the results: | |
Wrapper around a neural network implemented by with the tiny-dnn framework by Taiga Nomi.
Because tiny-dnn is an all-include package, we use the pimpl idiom here to avoid including all the tiny-dnn sources in the header file, and instead only include and compile them once in our ObjectRecognition.C file.
Definition at line 123 of file ObjectRecognition.H.
ObjectRecognition< NetType >::ObjectRecognition | ( | std::string const & | instance | ) |
Constructor allocates the (empty) network.
Definition at line 35 of file ObjectRecognition.C.
|
virtual |
Destructor.
Definition at line 107 of file ObjectRecognition.C.
|
overridevirtual |
Get the input size for the current network, useful to prepare inputs to process()
Implements ObjectRecognitionBase.
Definition at line 112 of file ObjectRecognition.C.
|
overrideprotectedvirtual |
Initialize the network, required before one starts using it.
First, we will call define(). Then, we will look in path for weights.tnn, and if not found, we will call train() to train the network using data in that path, and then we will save weights.tnn. Derived classes may implement a constructor that takes path and then calls init(path) after the base class has been constructed (e.g., in the body of the derived class constructor).
Reimplemented from jevois::Component.
Definition at line 41 of file ObjectRecognition.C.
References JEVOIS_SHARE_PATH, LERROR, LINFO, and jevois::warnAndIgnoreException().
|
overridevirtual |
Process an image, results are confidence for each category.
Implements ObjectRecognitionBase.
Definition at line 118 of file ObjectRecognition.C.
References LFATAL.
|
protected |
Definition at line 146 of file ObjectRecognition.H.
Referenced by PyNetKSNN.PyNetKSNN::load(), PyNetOpenCV.PyNetOpenCV::load(), PyDetectionDNN.PyDetectionDNN::postprocess(), PyNetKSNN.PyNetKSNN::process(), PyNetOpenCV.PyNetOpenCV::process(), PyClassificationDNN.PyClassificationDNN::process(), and PyDetectionDNN.PyDetectionDNN::process().