JeVoisBase  1.0
JeVois Smart Embedded Machine Vision Toolkit Base Modules
ObjectRecognition< NetType > Class Template Reference

Wrapper around a neural network implemented by with the tiny-dnn framework by Taiga Nomi. More...

#include </lab/itti/jevois/software/jevoisbase/src/Components/ObjectRecognition/ObjectRecognition.H>

Inheritance diagram for ObjectRecognition< NetType >:
Collaboration diagram for ObjectRecognition< NetType >:

Public Member Functions

 ObjectRecognition (std::string const &instance)
 Constructor allocates the (empty) network. More...
 
virtual ~ObjectRecognition ()
 Destructor. More...
 
virtual tiny_dnn::index3d< tiny_dnn::serial_size_t > insize () const override
 Get the input size for the current network, useful to prepare inputs to process() More...
 
vec_t process (cv::Mat const &img, bool normalize=true) override
 Process an image, results are confidence for each category. More...
 
- Public Member Functions inherited from ObjectRecognitionBase
 ObjectRecognitionBase (std::string const &instance)
 Constructor. More...
 
virtual ~ObjectRecognitionBase ()
 Virtual destructor for safe inheritance. More...
 
virtual void define ()=0
 Define the network structure. More...
 
virtual void train (std::string const &path)=0
 Train the network. More...
 
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) More...
 
- Public Member Functions inherited from jevois::Component
 Component (std::string const &instance)
 
virtual ~Component ()
 
std::shared_ptr< ComponentgetSubComponent (std::string const &instance) const
 
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 &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)
 
void setPath (std::string const &path)
 
std::string absolutePath (std::string 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 &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)
 
void setPath (std::string const &path)
 
std::string absolutePath (std::string 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. More...
 
- 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: More...
 

Detailed Description

template<typename NetType>
class ObjectRecognition< NetType >

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 81 of file ObjectRecognition.H.

Constructor & Destructor Documentation

template<typename NetType >
ObjectRecognition< NetType >::ObjectRecognition ( std::string const &  instance)

Constructor allocates the (empty) network.

Definition at line 35 of file ObjectRecognition.C.

template<typename NetType >
ObjectRecognition< NetType >::~ObjectRecognition ( )
virtual

Destructor.

Definition at line 70 of file ObjectRecognition.C.

Member Function Documentation

template<typename NetType >
tiny_dnn::index3d< tiny_dnn::serial_size_t > ObjectRecognition< NetType >::insize ( ) const
overridevirtual

Get the input size for the current network, useful to prepare inputs to process()

Implements ObjectRecognitionBase.

Definition at line 76 of file ObjectRecognition.C.

template<typename NetType >
void ObjectRecognition< NetType >::postInit ( )
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 LINFO.

template<typename NetType >
ObjectRecognition< NetType >::vec_t ObjectRecognition< NetType >::process ( cv::Mat const &  img,
bool  normalize = true 
)
overridevirtual

Process an image, results are confidence for each category.

Implements ObjectRecognitionBase.

Definition at line 82 of file ObjectRecognition.C.

References LFATAL.

Member Data Documentation

template<typename NetType>
tiny_dnn::network<NetType>* ObjectRecognition< NetType >::net
protected

Definition at line 104 of file ObjectRecognition.H.


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