JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
NetworkTPU.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2021 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#pragma once
19
20#ifdef JEVOIS_PRO
21
22#include <jevois/DNN/Network.H>
23#include <tensorflow/lite/model.h>
24
25namespace jevois
26{
27 namespace dnn
28 {
29 //! Wrapper around a Coral TPU neural network
30 /*! \ingroup dnn */
32 public jevois::Parameter<network::intensors, network::outtensors, network::dataroot,
33 network::model, network::tpunum, network::dequant>
34 {
35 public:
36 //! Inherited constructor ok
37 using jevois::dnn::Network::Network;
38
39 //! Destructor
40 virtual ~NetworkTPU();
41
42 //! Freeze/unfreeze parameters that users should not change while running
43 void freeze(bool doit) override;
44
45 //! Get shapes of all input tensors
46 virtual std::vector<vsi_nn_tensor_attr_t> inputShapes() override;
47
48 //! Get shapes of all output tensors
49 virtual std::vector<vsi_nn_tensor_attr_t> outputShapes() override;
50
51 protected:
52 //! Load from disk
53 void load() override;
54
55 //! Process input blobs and obtain output blobs
56 std::vector<cv::Mat> doprocess(std::vector<cv::Mat> const & blobs,
57 std::vector<std::string> & info) override;
58
59 private:
60 std::unique_ptr<tflite::Interpreter> itsInterpreter;
61 std::unique_ptr<tflite::FlatBufferModel> itsModel;
62
63 struct ErrorReporter : public tflite::ErrorReporter
64 {
65 int Report(char const * format, va_list args) override;
66 std::vector<std::string> itsErrors;
67 };
68
69 ErrorReporter itsErrorReporter;
70 };
71
72 } // namespace dnn
73} // namespace jevois
74
75#endif // JEVOIS_PRO
Wrapper around a Coral TPU neural network.
Definition NetworkTPU.H:34
void load() override
Load from disk.
Definition NetworkTPU.C:103
void freeze(bool doit) override
Freeze/unfreeze parameters that users should not change while running.
Definition NetworkTPU.C:45
virtual ~NetworkTPU()
Destructor.
Definition NetworkTPU.C:41
virtual std::vector< vsi_nn_tensor_attr_t > outputShapes() override
Get shapes of all output tensors.
Definition NetworkTPU.C:80
virtual std::vector< vsi_nn_tensor_attr_t > inputShapes() override
Get shapes of all input tensors.
Definition NetworkTPU.C:57
std::vector< cv::Mat > doprocess(std::vector< cv::Mat > const &blobs, std::vector< std::string > &info) override
Process input blobs and obtain output blobs.
Definition NetworkTPU.C:168
Abstract class to represent a neural network.
Definition Network.H:212
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2