openvino/inference-engine/include/cpp/ie_cnn_net_reader.h

147 lines
3.7 KiB
C
Raw Normal View History

2019-04-12 10:25:53 -05:00
// Copyright (C) 2018-2019 Intel Corporation
2018-10-16 05:45:03 -05:00
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief This is a header file for the Network reader class (wrapper) used to build networks from a given IR
* @file ie_cnn_net_reader.h
*/
#pragma once
#include <string>
#include <vector>
#include <memory>
#include <map>
#include "ie_blob.h"
#include "ie_cnn_network.h"
#include "ie_common.h"
#include "ie_icnn_net_reader.h"
#include "details/ie_exception_conversion.hpp"
2019-08-09 11:02:42 -05:00
#include "details/os/os_filesystem.hpp"
2018-10-16 05:45:03 -05:00
namespace InferenceEngine {
/**
* @brief This is a wrapper class used to build and parse a network from the given IR.
* All the methods here can throw exceptions.
*/
class CNNNetReader {
public:
/**
* @brief A smart pointer to this class
*/
using Ptr = std::shared_ptr<CNNNetReader>;
/**
* @brief A default constructor
*/
CNNNetReader() : actual(shared_from_irelease(InferenceEngine::CreateCNNNetReader())) {}
2019-08-09 11:02:42 -05:00
#ifdef ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Resolve wstring path then call orginal ReadNetwork
* ICNNNetReader::ReadNetwork
*/
void ReadNetwork(const std::wstring &filepath) {
CALL_STATUS_FNC(ReadNetwork, details::wStringtoMBCSstringChar(filepath).c_str());
}
#endif
2018-10-16 05:45:03 -05:00
/**
* @brief Wraps original method
* ICNNNetReader::ReadNetwork
*/
void ReadNetwork(const std::string &filepath) {
CALL_STATUS_FNC(ReadNetwork, filepath.c_str());
}
/**
* @brief Wraps original method
* ICNNNetReader::ReadNetwork(const void*, size_t, ResponseDesc*)
*/
void ReadNetwork(const void *model, size_t size) {
CALL_STATUS_FNC(ReadNetwork, model, size);
}
/**
* @brief Wraps original method
* ICNNNetReader::SetWeights
*/
2019-08-09 11:02:42 -05:00
void SetWeights(const TBlob<uint8_t>::Ptr &weights) {
2018-10-16 05:45:03 -05:00
CALL_STATUS_FNC(SetWeights, weights);
}
2019-08-09 11:02:42 -05:00
#ifdef ENABLE_UNICODE_PATH_SUPPORT
/**
* @brief Resolve wstring path then call orginal ReadWeights
* ICNNNetReader::ReadWeights
*/
void ReadWeights(const std::wstring &filepath) {
CALL_STATUS_FNC(ReadWeights, details::wStringtoMBCSstringChar(filepath).c_str());
}
#endif
2018-10-16 05:45:03 -05:00
/**
* @brief Wraps original method
* ICNNNetReader::ReadWeights
*/
2019-08-09 11:02:42 -05:00
void ReadWeights(const std::string &filepath) {
2018-10-16 05:45:03 -05:00
CALL_STATUS_FNC(ReadWeights, filepath.c_str());
}
/**
* @brief Gets a copy of built network object
* @return A copy of the CNNNetwork object to be loaded
*/
CNNNetwork getNetwork() {
// network obj are to be updated upon this call
if (network.get() == nullptr) {
2018-11-23 07:19:43 -06:00
try {
network.reset(new CNNNetwork(actual));
} catch (...) {
THROW_IE_EXCEPTION << "Could not allocate memory";
}
2018-10-16 05:45:03 -05:00
}
return *network.get();
}
/**
* @brief Wraps original method
* ICNNNetReader::isParseSuccess
*/
bool isParseSuccess() const {
CALL_FNC_NO_ARGS(isParseSuccess);
}
/**
* @brief Wraps original method
* ICNNNetReader::getDescription
*/
std::string getDescription() const {
CALL_STATUS_FNC_NO_ARGS(getDescription);
return resp.msg;
}
/**
* @brief Wraps original method
* ICNNNetReader::getName
*/
std::string getName() const {
char name[64];
CALL_STATUS_FNC(getName, name, sizeof(name) / sizeof(*name));
return name;
}
/**
* @brief Wraps original method
* ICNNNetReader::getVersion
*/
int getVersion() const {
CALL_FNC_NO_ARGS(getVersion);
}
private:
std::shared_ptr<ICNNNetReader> actual;
std::shared_ptr<CNNNetwork> network;
};
} // namespace InferenceEngine