Files
openvino/inference-engine/include/ie_input_info.hpp

168 lines
4.7 KiB
C++
Raw Normal View History

2020-02-11 22:48:49 +03:00
// Copyright (C) 2018-2020 Intel Corporation
2018-10-16 13:45:03 +03:00
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief a header file for InputInfo class
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* @file ie_input_info.hpp
*/
#pragma once
#include <map>
2020-02-11 22:48:49 +03:00
#include <memory>
#include <string>
#include "ie_blob.h"
2018-10-16 13:45:03 +03:00
#include "ie_common.h"
#include "ie_data.h"
#include "ie_precision.hpp"
2020-02-11 22:48:49 +03:00
#include "ie_preprocess.hpp"
2018-10-16 13:45:03 +03:00
namespace InferenceEngine {
/**
* @brief This class contains information about each input of the network
*/
class InputInfo {
public:
/** @brief A smart pointer to the InputInfo instance */
using Ptr = std::shared_ptr<InputInfo>;
/** @brief A smart pointer to the constant InputInfo instance */
using CPtr = std::shared_ptr<const InputInfo>;
/**
* @brief Gets a precision of the input data provided by user
*
* By default it matches the layers precision, but there are exceptions of this rule
* For Q78 precision networks the input is expected in I16 by default
* For FP16 precision networks the input is expected in FP32 by default
2019-08-09 19:02:42 +03:00
* The default input precision might be changed preferred one using InputInfo::setPrecision()
2018-10-16 13:45:03 +03:00
* function.
* For example, for a Q78 precision network you can pass FP32 input data
* @return The precision used for input blob creation
*/
Precision getPrecision() const {
if (!_inputData) {
THROW_IE_EXCEPTION << "Data is empty!";
}
return _inputData->getPrecision();
}
/**
* @brief Changes the precision of the input data provided by the user.
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* This function should be called before loading the network to the plugin
* @param p A new precision of the input data to set
*/
void setPrecision(Precision p) {
if (!_inputData) {
THROW_IE_EXCEPTION << "Data is empty!";
}
_inputData->setPrecision(p);
}
/**
* @brief Gets a layout of the input data provided by user
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* @details By default it matches the layers precision and depends on number of its dimensions:
* C - for 1-dimensional,
* NC - for 2-dimensional,
* CHW - for 3-dimensional,
* NCHW - for 4-dimensional
* The default input layout might be changed preferred one using setLayout() function.
* @return The precision used for input blob creation
*/
Layout getLayout() {
if (!_inputData) {
THROW_IE_EXCEPTION << "Data is empty!";
}
return _inputData->getLayout();
}
/**
* @brief Changes the layout of the input data provided by the user.
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* This function should be called before loading the network to the plugin
2020-04-13 21:17:23 +03:00
* @param l A new layout of the input data to set
2018-10-16 13:45:03 +03:00
*/
void setLayout(Layout l) {
if (!_inputData) {
THROW_IE_EXCEPTION << "Data is empty!";
}
_inputData->setLayout(l);
}
/**
* @brief Gets the name of the input
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* @return A string - the name of the input
*/
2020-02-11 22:48:49 +03:00
const std::string& name() const {
return _inputData->getName();
}
2018-10-16 13:45:03 +03:00
/**
* @brief Gets the input data
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* @return A smart pointer to the input data
*/
2020-02-11 22:48:49 +03:00
DataPtr getInputData() const {
2018-10-16 13:45:03 +03:00
return _inputData;
}
/**
2020-04-13 21:17:23 +03:00
* @brief Initializes the pointer to the input data that stores the main input parameters like dims, etc
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* This method initializes the precision with the information from the inputPtr if it was not set
2020-02-11 22:48:49 +03:00
* explicitly through InputInfo::setPrecision. If InputInfo::setPrecision is called, this method does not overwrite
* the precision.
2018-10-16 13:45:03 +03:00
* @param inputPtr Pointer to the input data to set
*/
void setInputData(DataPtr inputPtr) {
_inputData = inputPtr;
}
/**
* @brief Returns the tensor descriptor
*/
2020-02-11 22:48:49 +03:00
const TensorDesc& getTensorDesc() const {
2018-10-16 13:45:03 +03:00
if (!_inputData) {
THROW_IE_EXCEPTION << "Data is empty!";
}
return _inputData->getTensorDesc();
}
/**
* @brief Gets pre-process info for the input
2020-02-11 22:48:49 +03:00
*
2018-10-16 13:45:03 +03:00
* @return A reference to the PreProcessInfo instance that contains pre-process info for this input
*/
2020-02-11 22:48:49 +03:00
PreProcessInfo& getPreProcess() {
return _preProcessInfo;
}
2018-10-16 13:45:03 +03:00
protected:
/**
* @brief Pre-process info for the input
*/
PreProcessInfo _preProcessInfo;
/**
* @brief A smart pointer to the input data
*/
DataPtr _inputData;
};
/**
* @brief A collection that contains string as key, and InputInfo smart pointer as value
*/
using InputsDataMap = std::map<std::string, InputInfo::Ptr>;
/**
* @brief A collection that contains string as key, and const InputInfo smart pointer as value
*/
using ConstInputsDataMap = std::map<std::string, InputInfo::CPtr>;
} // namespace InferenceEngine