JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
|
Identify an object using TensorFlow deep neural network. More...
#include <jevoisbase/Components/ObjectDetection/TensorFlow.H>
Classes | |
struct | JeVoisReporter |
Public Member Functions | |
TensorFlow (std::string const &instance) | |
Constructor. | |
void | postInit () override |
Initialize, configure and load the network in a thread. | |
virtual | ~TensorFlow () |
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 TensorFlow network object. | |
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 | |
std::vector< std::string > | labels |
size_t | numlabels |
std::unique_ptr< tflite::FlatBufferModel > | model |
std::unique_ptr< tflite::Interpreter > | interpreter |
Protected Member Functions | |
void | onParamChange (tflow::netdir const ¶m, std::string const &newval) override |
void | onParamChange (tflow::dataroot const ¶m, std::string const &newval) override |
void | loadNet () |
void | readLabelsFile (std::string const &fname) |
template<class T > | |
void | get_top_n (T *prediction, int prediction_size, std::vector< jevois::ObjReco > &top_results, bool input_floating) |
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 |
std::atomic< bool > | itsNeedReload |
JeVoisReporter | itsErrorReporter |
Related Symbols | |
(Note that these are not member symbols.) | |
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK (netdir, std::string, "Network to load. This should be the name of a " "directory within JEVOIS:/share/tensorflow/ which should contain two files: " "model.tflite and labels.txt", "mobilenet_v1_224_android_quant_2017_11_08", 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 "/tensorflow", 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, or 0 for auto", 4, jevois::Range< int >(0, 1024), ParamCateg) | |
Parameter. | |
JEVOIS_DECLARE_PARAMETER (scorescale, float, "Scaling factors applied to recognition scores, useful for InceptionV3", 1.0F, ParamCateg) | |
Parameter. | |
Identify an object using TensorFlow deep neural network.
TensorFlow is a popular neural network framework. This component identifies the object in the given image crop. It returns the top scoring candidates.
See https://www.tensorflow.org
TensorFlow is a great deep learning and deep neural network framework. TensorFlow Lite (used here) is optimized 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 MXNet, Theano, Keras, PyTorch, etc. In addition, the port of TensorFlow to JeVois includes acceleration using the ARM NEON multimedia instructions.
Definition at line 73 of file TensorFlow.H.
TensorFlow::TensorFlow | ( | std::string const & | instance | ) |
Constructor.
Definition at line 51 of file TensorFlow.C.
|
virtual |
Virtual destructor for safe inheritance.
Definition at line 56 of file TensorFlow.C.
References itsReadyFut, and JEVOIS_WAIT_GET_FUTURE.
|
protected |
Definition at line 97 of file TensorFlow.C.
References labels.
void TensorFlow::getInDims | ( | int & | w, |
int & | h, | ||
int & | c | ||
) |
Get input width, height, channels.
Throws std::logic_error if the network is still loading and not ready.
Definition at line 296 of file TensorFlow.C.
References h, interpreter, itsNeedReload, itsReady, and loadNet().
|
protected |
Definition at line 134 of file TensorFlow.C.
References jevois::Component::absolutePath(), jevois::async(), interpreter, itsErrorReporter, itsNeedReload, itsReady, itsReadyFut, labels, LFATAL, LINFO, model, numlabels, and readLabelsFile().
Referenced by getInDims(), postInit(), and predict().
|
overrideprotected |
Definition at line 67 of file TensorFlow.C.
References itsNeedReload.
|
overrideprotected |
Definition at line 63 of file TensorFlow.C.
References itsNeedReload.
|
overridevirtual |
Initialize, configure and load the network in a thread.
Any call to predict() will simply throw until the network is loaded and ready
Reimplemented from jevois::Component.
Definition at line 89 of file TensorFlow.C.
References loadNet().
|
overridevirtual |
Un-initialize and free resources.
Reimplemented from jevois::Component.
Definition at line 214 of file TensorFlow.C.
References itsReadyFut.
float TensorFlow::predict | ( | cv::Mat const & | cvimg, |
std::vector< jevois::ObjReco > & | results | ||
) |
Processing function, results are stored internally in the underlying TensorFlow network object.
Expects an OpenCV byte RGB (CV_8UC3) or Gray (CV_8UC1) image, which may be further converted to float if that is what the network wants as input. The image dims and number of channels must match the network's input dims and channels. 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 220 of file TensorFlow.C.
References interpreter, itsNeedReload, itsReady, LFATAL, loadNet(), and numlabels.
|
protected |
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
|
related |
Parameter.
std::unique_ptr<tflite::Interpreter> TensorFlow::interpreter |
Definition at line 106 of file TensorFlow.H.
Referenced by getInDims(), loadNet(), predict(), PyCoralClassify.PyCoralClassify::process(), PyCoralDetect.PyCoralDetect::process(), PyCoralSegment.PyCoralSegment::process(), PyCoralClassify.PyCoralClassify::processGUI(), PyCoralDetect.PyCoralDetect::processGUI(), and PyCoralSegment.PyCoralSegment::processGUI().
|
protected |
Definition at line 127 of file TensorFlow.H.
Referenced by loadNet().
|
protected |
Definition at line 120 of file TensorFlow.H.
Referenced by getInDims(), loadNet(), onParamChange(), onParamChange(), and predict().
|
protected |
Definition at line 119 of file TensorFlow.H.
Referenced by getInDims(), loadNet(), and predict().
|
protected |
Definition at line 118 of file TensorFlow.H.
Referenced by loadNet(), postUninit(), and ~TensorFlow().
std::vector<std::string> TensorFlow::labels |
Definition at line 103 of file TensorFlow.H.
Referenced by mobilenet_v1.MobileNetV1::_postprocess(), mobilenet_v2.MobileNetV2::_postprocess(), get_top_n(), loadNet(), PyCoralClassify.PyCoralClassify::process(), PyCoralDetect.PyCoralDetect::process(), PyCoralClassify.PyCoralClassify::processGUI(), PyCoralDetect.PyCoralDetect::processGUI(), and readLabelsFile().
std::unique_ptr<tflite::FlatBufferModel> TensorFlow::model |
Definition at line 105 of file TensorFlow.H.
Referenced by lpd_yunet.LPD_YuNet::__init__(), PyNetKSNN.PyNetKSNN::freeze(), PyNetOpenCV.PyNetOpenCV::freeze(), PyNetORT.PyNetORT::freeze(), PyNetURetinex.PyNetURetinex::freeze(), mobilenet_v1.MobileNetV1::infer(), mobilenet_v2.MobileNetV2::infer(), lpd_yunet.LPD_YuNet::infer(), mp_palmdet.MPPalmDet::infer(), PyNetKSNN.PyNetKSNN::load(), PyNetOpenCV.PyNetOpenCV::load(), PyNetORT.PyNetORT::load(), PyNetURetinex.PyNetURetinex::load(), loadNet(), PyClassificationDNN.PyClassificationDNN::process(), PyCoralClassify.PyCoralClassify::process(), PyCoralDetect.PyCoralDetect::process(), PyCoralSegment.PyCoralSegment::process(), PyDetectionDNN.PyDetectionDNN::process(), PyCoralClassify.PyCoralClassify::processGUI(), PyCoralDetect.PyCoralDetect::processGUI(), PyCoralSegment.PyCoralSegment::processGUI(), PyLicensePlate.PyLicensePlate::processGUI(), mobilenet_v1.MobileNetV1::setBackend(), mobilenet_v2.MobileNetV2::setBackend(), lpd_yunet.LPD_YuNet::setBackend(), mp_palmdet.MPPalmDet::setBackend(), mobilenet_v1.MobileNetV1::setTarget(), mobilenet_v2.MobileNetV2::setTarget(), lpd_yunet.LPD_YuNet::setTarget(), and mp_palmdet.MPPalmDet::setTarget().
size_t TensorFlow::numlabels |
Definition at line 104 of file TensorFlow.H.
Referenced by loadNet(), predict(), and readLabelsFile().