ie_cnn_net_reader.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief This is a header file for the Network reader class (wrapper) used to build networks from a given IR
7  * @file ie_cnn_net_reader.h
8  */
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 #include <memory>
14 #include <map>
15 #include "ie_blob.h"
16 #include "ie_cnn_network.h"
17 #include "ie_common.h"
18 #include "ie_icnn_net_reader.h"
20 
21 namespace InferenceEngine {
22 /**
23  * @brief This is a wrapper class used to build and parse a network from the given IR.
24  * All the methods here can throw exceptions.
25  */
26 class CNNNetReader {
27 public:
28  /**
29  * @brief A smart pointer to this class
30  */
31  using Ptr = std::shared_ptr<CNNNetReader>;
32 
33  /**
34  * @brief A default constructor
35  */
36  CNNNetReader() : actual(shared_from_irelease(InferenceEngine::CreateCNNNetReader())) {}
37 
38  /**
39  * @brief Wraps original method
40  * ICNNNetReader::ReadNetwork
41  */
42  void ReadNetwork(const std::string &filepath) {
43  CALL_STATUS_FNC(ReadNetwork, filepath.c_str());
44  }
45 
46  /**
47  * @brief Wraps original method
48  * ICNNNetReader::ReadNetwork(const void*, size_t, ResponseDesc*)
49  */
50  void ReadNetwork(const void *model, size_t size) {
51  CALL_STATUS_FNC(ReadNetwork, model, size);
52  }
53 
54  /**
55  * @brief Wraps original method
56  * ICNNNetReader::SetWeights
57  */
58  void SetWeights(const TBlob<uint8_t>::Ptr &weights) const {
59  CALL_STATUS_FNC(SetWeights, weights);
60  }
61 
62  /**
63  * @brief Wraps original method
64  * ICNNNetReader::ReadWeights
65  */
66  void ReadWeights(const std::string &filepath) const {
67  CALL_STATUS_FNC(ReadWeights, filepath.c_str());
68  }
69 
70  /**
71  * @brief Gets a copy of built network object
72  * @return A copy of the CNNNetwork object to be loaded
73  */
75  // network obj are to be updated upon this call
76  if (network.get() == nullptr) {
77  try {
78  network.reset(new CNNNetwork(actual));
79  } catch (...) {
80  THROW_IE_EXCEPTION << "Could not allocate memory";
81  }
82  }
83  return *network.get();
84  }
85 
86  /**
87  * @brief Wraps original method
88  * ICNNNetReader::isParseSuccess
89  */
90  bool isParseSuccess() const {
91  CALL_FNC_NO_ARGS(isParseSuccess);
92  }
93 
94  /**
95  * @brief Wraps original method
96  * ICNNNetReader::getDescription
97  */
98  std::string getDescription() const {
99  CALL_STATUS_FNC_NO_ARGS(getDescription);
100  return resp.msg;
101  }
102 
103  /**
104  * @brief Wraps original method
105  * ICNNNetReader::getName
106  */
107  std::string getName() const {
108  char name[64];
109  CALL_STATUS_FNC(getName, name, sizeof(name) / sizeof(*name));
110  return name;
111  }
112 
113  /**
114  * @brief Wraps original method
115  * ICNNNetReader::getVersion
116  */
117  int getVersion() const {
118  CALL_FNC_NO_ARGS(getVersion);
119  }
120 
121 private:
122  std::shared_ptr<ICNNNetReader> actual;
123  std::shared_ptr<CNNNetwork> network;
124 };
125 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
A header file that provides wrapper for ICNNNetwork object.
void ReadWeights(const std::string &filepath) const
Wraps original method ICNNNetReader::ReadWeights.
Definition: ie_cnn_net_reader.h:66
Definition: ie_argmax_layer.hpp:11
A header file that provides macros to handle no exception methods.
This is a wrapper class used to build and parse a network from the given IR. All the methods here can...
Definition: ie_cnn_net_reader.h:26
std::shared_ptr< CNNNetReader > Ptr
A smart pointer to this class.
Definition: ie_cnn_net_reader.h:31
A header file for Blob and generic TBlob<>
std::string getName() const
Wraps original method ICNNNetReader::getName.
Definition: ie_cnn_net_reader.h:107
ICNNNetReader * CreateCNNNetReader() noexcept
Creates a CNNNetReader instance.
std::shared_ptr< TBlob< T >> Ptr
Smart Pointer to this TBlob object.
Definition: ie_blob.h:274
CNNNetwork getNetwork()
Gets a copy of built network object.
Definition: ie_cnn_net_reader.h:74
void ReadNetwork(const void *model, size_t size)
Wraps original method ICNNNetReader::ReadNetwork(const void*, size_t, ResponseDesc*) ...
Definition: ie_cnn_net_reader.h:50
This class contains all the information about the Neural Network and the related binary information...
Definition: ie_cnn_network.h:29
int getVersion() const
Wraps original method ICNNNetReader::getVersion.
Definition: ie_cnn_net_reader.h:117
CNNNetReader()
A default constructor.
Definition: ie_cnn_net_reader.h:36
A header file that provides interface for network reader that is used to build networks from a given ...
bool isParseSuccess() const
Wraps original method ICNNNetReader::isParseSuccess.
Definition: ie_cnn_net_reader.h:90
void SetWeights(const TBlob< uint8_t >::Ptr &weights) const
Wraps original method ICNNNetReader::SetWeights.
Definition: ie_cnn_net_reader.h:58
void ReadNetwork(const std::string &filepath)
Wraps original method ICNNNetReader::ReadNetwork.
Definition: ie_cnn_net_reader.h:42
std::string getDescription() const
Wraps original method ICNNNetReader::getDescription.
Definition: ie_cnn_net_reader.h:98
This is a header file with common inference engine definitions.