JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
NetworkONNX.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 <jevois/Types/Enum.H>
24#include <onnxruntime_cxx_api.h>
25#include <opencv2/core.hpp>
26
27namespace jevois
28{
29 namespace dnn
30 {
31 //! Wrapper around an ONNX-Runtime neural network
32 /*! \ingroup dnn */
34 public jevois::Parameter<network::dataroot, network::model>
35 {
36 public:
37 //! Inherited constructor ok
38 NetworkONNX(std::string const & instance);
39
40 //! Destructor
41 virtual ~NetworkONNX();
42
43 //! Freeze/unfreeze parameters that users should not change while running
44 void freeze(bool doit) override;
45
46 //! Get shapes of all input tensors
47 virtual std::vector<vsi_nn_tensor_attr_t> inputShapes() override;
48
49 //! Get shapes of all output tensors
50 virtual std::vector<vsi_nn_tensor_attr_t> outputShapes() override;
51
52 protected:
53 //! Load from disk
54 void load() override;
55
56 //! Process input blobs and obtain output blobs
57 std::vector<cv::Mat> doprocess(std::vector<cv::Mat> const & blobs,
58 std::vector<std::string> & info) override;
59
60 private:
61 std::shared_ptr<Ort::Session> itsSession;
62 Ort::Env itsEnv;
63 Ort::SessionOptions itsSessionOptions;
64 std::vector<vsi_nn_tensor_attr_t> itsInAttrs;
65 std::vector<vsi_nn_tensor_attr_t> itsOutAttrs;
66
67 std::vector<Ort::AllocatedStringPtr> itsInNamePtrs;
68 std::vector<char const *> itsInNames;
69 std::vector<Ort::AllocatedStringPtr> itsOutNamePtrs;
70 std::vector<char const *> itsOutNames;
71
72 std::vector<Ort::Value> itsOutputs;
73 };
74
75 } // namespace dnn
76} // namespace jevois
77
78#endif // JEVOIS_PRO
Wrapper around an ONNX-Runtime neural network.
Definition NetworkONNX.H:35
std::vector< cv::Mat > doprocess(std::vector< cv::Mat > const &blobs, std::vector< std::string > &info) override
Process input blobs and obtain output blobs.
void freeze(bool doit) override
Freeze/unfreeze parameters that users should not change while running.
Definition NetworkONNX.C:38
virtual ~NetworkONNX()
Destructor.
Definition NetworkONNX.C:34
void load() override
Load from disk.
Definition NetworkONNX.C:60
virtual std::vector< vsi_nn_tensor_attr_t > inputShapes() override
Get shapes of all input tensors.
Definition NetworkONNX.C:46
virtual std::vector< vsi_nn_tensor_attr_t > outputShapes() override
Get shapes of all output tensors.
Definition NetworkONNX.C:53
Abstract class to represent a neural network.
Definition Network.H:212
Main namespace for all JeVois classes and functions.
Definition Concepts.dox:2