Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / include / cpp / ie_cnn_net_reader.h
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"
19 #include "details/ie_exception_conversion.hpp"
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      */
74     CNNNetwork getNetwork() {
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