ie_cnn_net_reader.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 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 #include "details/os/os_filesystem.hpp"
21 
22 namespace InferenceEngine {
23 /**
24  * @brief This is a wrapper class used to build and parse a network from the given IR.
25  * All the methods here can throw exceptions.
26  */
27 class CNNNetReader {
28 public:
29  /**
30  * @brief A smart pointer to this class
31  */
32  using Ptr = std::shared_ptr<CNNNetReader>;
33 
34  /**
35  * @brief A default constructor
36  */
37  CNNNetReader() : actual(shared_from_irelease(InferenceEngine::CreateCNNNetReader())) {}
38 
39 #ifdef ENABLE_UNICODE_PATH_SUPPORT
40  /**
41  * @brief Resolve wstring path then call orginal ReadNetwork
42  * ICNNNetReader::ReadNetwork
43  */
44  void ReadNetwork(const std::wstring &filepath) {
45  CALL_STATUS_FNC(ReadNetwork, details::wStringtoMBCSstringChar(filepath).c_str());
46  }
47 #endif
48 
49  /**
50  * @brief Wraps original method
51  * ICNNNetReader::ReadNetwork
52  */
53  void ReadNetwork(const std::string &filepath) {
54  CALL_STATUS_FNC(ReadNetwork, filepath.c_str());
55  }
56 
57  /**
58  * @brief Wraps original method
59  * ICNNNetReader::ReadNetwork(const void*, size_t, ResponseDesc*)
60  */
61  void ReadNetwork(const void *model, size_t size) {
62  CALL_STATUS_FNC(ReadNetwork, model, size);
63  }
64 
65  /**
66  * @brief Wraps original method
67  * ICNNNetReader::SetWeights
68  */
69  void SetWeights(const TBlob<uint8_t>::Ptr &weights) {
70  CALL_STATUS_FNC(SetWeights, weights);
71  }
72 
73 #ifdef ENABLE_UNICODE_PATH_SUPPORT
74  /**
75  * @brief Resolve wstring path then call orginal ReadWeights
76  * ICNNNetReader::ReadWeights
77  */
78  void ReadWeights(const std::wstring &filepath) {
79  CALL_STATUS_FNC(ReadWeights, details::wStringtoMBCSstringChar(filepath).c_str());
80  }
81 #endif
82 
83  /**
84  * @brief Wraps original method
85  * ICNNNetReader::ReadWeights
86  */
87  void ReadWeights(const std::string &filepath) {
88  CALL_STATUS_FNC(ReadWeights, filepath.c_str());
89  }
90 
91  /**
92  * @brief Gets a copy of built network object
93  * @return A copy of the CNNNetwork object to be loaded
94  */
96  // network obj are to be updated upon this call
97  if (network.get() == nullptr) {
98  try {
99  network.reset(new CNNNetwork(actual));
100  } catch (...) {
101  THROW_IE_EXCEPTION << "Could not allocate memory";
102  }
103  }
104  return *network.get();
105  }
106 
107  /**
108  * @brief Wraps original method
109  * ICNNNetReader::isParseSuccess
110  */
111  bool isParseSuccess() const {
112  CALL_FNC_NO_ARGS(isParseSuccess);
113  }
114 
115  /**
116  * @brief Wraps original method
117  * ICNNNetReader::getDescription
118  */
119  std::string getDescription() const {
120  CALL_STATUS_FNC_NO_ARGS(getDescription);
121  return resp.msg;
122  }
123 
124  /**
125  * @brief Wraps original method
126  * ICNNNetReader::getName
127  */
128  std::string getName() const {
129  char name[64];
130  CALL_STATUS_FNC(getName, name, sizeof(name) / sizeof(*name));
131  return name;
132  }
133 
134  /**
135  * @brief Wraps original method
136  * ICNNNetReader::getVersion
137  */
138  int getVersion() const {
139  CALL_FNC_NO_ARGS(getVersion);
140  }
141 
142 private:
143  std::shared_ptr<ICNNNetReader> actual;
144  std::shared_ptr<CNNNetwork> network;
145 };
146 } // 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.
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:27
std::shared_ptr< CNNNetReader > Ptr
A smart pointer to this class.
Definition: ie_cnn_net_reader.h:32
A header file for Blob and generic TBlob<>
std::string getName() const
Wraps original method ICNNNetReader::getName.
Definition: ie_cnn_net_reader.h:128
ICNNNetReader * CreateCNNNetReader() noexcept
Creates a CNNNetReader instance.
std::shared_ptr< TBlob< T >> Ptr
Smart Pointer to this TBlob object.
Definition: ie_blob.h:493
CNNNetwork getNetwork()
Gets a copy of built network object.
Definition: ie_cnn_net_reader.h:95
void ReadNetwork(const void *model, size_t size)
Wraps original method ICNNNetReader::ReadNetwork(const void*, size_t, ResponseDesc*) ...
Definition: ie_cnn_net_reader.h:61
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:138
void SetWeights(const TBlob< uint8_t >::Ptr &weights)
Wraps original method ICNNNetReader::SetWeights.
Definition: ie_cnn_net_reader.h:69
CNNNetReader()
A default constructor.
Definition: ie_cnn_net_reader.h:37
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:111
void ReadNetwork(const std::string &filepath)
Wraps original method ICNNNetReader::ReadNetwork.
Definition: ie_cnn_net_reader.h:53
std::string getDescription() const
Wraps original method ICNNNetReader::getDescription.
Definition: ie_cnn_net_reader.h:119
void ReadWeights(const std::string &filepath)
Wraps original method ICNNNetReader::ReadWeights.
Definition: ie_cnn_net_reader.h:87
This is a header file with common inference engine definitions.