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