46 INFERENCE_ENGINE_DEPRECATED(
47 "InferenceEngine utility functions are not a part of public API. Will be removed in 2020.3")
48 inline
void TopResults(
unsigned int n,
TBlob<T>& input, std::vector<
unsigned>& output) {
49 SizeVector dims = input.getTensorDesc().getDims();
50 size_t input_rank = dims.size();
51 if (!input_rank || !dims[0])
THROW_IE_EXCEPTION <<
"Input blob has incorrect dimensions!";
52 size_t batchSize = dims[0];
53 std::vector<unsigned> indexes(input.size() / batchSize);
55 n =
static_cast<unsigned>(std::min<size_t>((size_t)n, input.size()));
57 output.resize(n * batchSize);
59 for (
size_t i = 0; i < batchSize; i++) {
60 size_t offset = i * (input.size() / batchSize);
61 T* batchData = input.data();
64 std::iota(std::begin(indexes), std::end(indexes), 0);
65 std::partial_sort(std::begin(indexes), std::begin(indexes) + n, std::end(indexes),
66 [&batchData](
unsigned l,
unsigned r) {
67 return batchData[l] > batchData[r];
69 for (
unsigned j = 0; j < n; j++) {
70 output.at(i * n + j) = indexes.at(j);
75 #define TBLOB_TOP_RESULT(precision) \ 76 case InferenceEngine::Precision::precision: { \ 77 using myBlobType = InferenceEngine::PrecisionTrait<Precision::precision>::value_type; \ 78 TBlob<myBlobType>& tblob = dynamic_cast<TBlob<myBlobType>&>(input); \ 79 TopResults(n, tblob, output); \ 91 INFERENCE_ENGINE_DEPRECATED(
92 "InferenceEngine utility functions are not a part of public API. Will be removed in 2020.3")
93 inline
void TopResults(
unsigned int n,
Blob& input, std::vector<
unsigned>& output) {
94 IE_SUPPRESS_DEPRECATED_START
95 switch (input.getTensorDesc().getPrecision()) {
96 TBLOB_TOP_RESULT(FP32);
97 TBLOB_TOP_RESULT(FP16);
98 TBLOB_TOP_RESULT(Q78);
99 TBLOB_TOP_RESULT(I16);
100 TBLOB_TOP_RESULT(U8);
101 TBLOB_TOP_RESULT(I8);
102 TBLOB_TOP_RESULT(U16);
103 TBLOB_TOP_RESULT(I32);
104 TBLOB_TOP_RESULT(U64);
105 TBLOB_TOP_RESULT(I64);
107 THROW_IE_EXCEPTION <<
"cannot locate blob for precision: " << input.getTensorDesc().getPrecision();
109 IE_SUPPRESS_DEPRECATED_END
112 #undef TBLOB_TOP_RESULT 125 template <
typename data_t>
126 INFERENCE_ENGINE_DEPRECATED(
127 "InferenceEngine utility functions are not a part of public API. Will be removed in 2020.3")
129 SizeVector dims = blob->getTensorDesc().getDims();
130 if (4 != dims.size())
131 THROW_IE_EXCEPTION <<
"Cannot write data to input blob! Blob has incorrect dimensions size " << dims.size();
132 size_t num_channels = dims[1];
133 size_t num_images = dims[0];
136 size_t nPixels = w * h;
138 if (RGB8_size != w * h * num_channels * num_images)
139 THROW_IE_EXCEPTION <<
"input pixels mismatch, expecting " << w * h * num_channels * num_images
140 <<
" bytes, got: " << RGB8_size;
142 std::vector<data_t*> dataArray;
143 for (
unsigned int n = 0; n < num_images; n++) {
144 for (
unsigned int i = 0; i < num_channels; i++) {
145 if (!n && !i && dataArray.empty()) {
146 dataArray.push_back(blob->data());
148 dataArray.push_back(dataArray.at(n * num_channels + i - 1) + nPixels);
152 for (
size_t n = 0; n < num_images; n++) {
153 size_t n_num_channels = n * num_channels;
154 size_t n_num_channels_nPixels = n_num_channels * nPixels;
155 for (
size_t i = 0; i < nPixels; i++) {
156 size_t i_num_channels = i * num_channels + n_num_channels_nPixels;
157 for (
size_t j = 0; j < num_channels; j++) {
158 dataArray.at(n_num_channels + j)[i] = RGB8[i_num_channels + j];
174 INFERENCE_ENGINE_DEPRECATED(
175 "InferenceEngine utility functions are not a part of public API. Will be removed in 2020.3")
177 IE_SUPPRESS_DEPRECATED_START
179 if (float_input !=
nullptr)
copyFromRGB8(imgBufRGB8, lengthbytesSize, float_input);
182 if (short_input !=
nullptr)
copyFromRGB8(imgBufRGB8, lengthbytesSize, short_input);
185 if (byte_input !=
nullptr)
copyFromRGB8(imgBufRGB8, lengthbytesSize, byte_input);
186 IE_SUPPRESS_DEPRECATED_END
196 template <
typename T>
197 INFERENCE_ENGINE_DEPRECATED(
198 "InferenceEngine utility functions are not a part of public API. Will be removed in 2020.3")
204 if (t_blob ==
nullptr) {
205 THROW_IE_EXCEPTION <<
"input type is " << src->getTensorDesc().getPrecision() <<
" but input is not " 209 const T* srcPtr = t_blob->
readOnly();
210 if (srcPtr ==
nullptr) {
213 for (
size_t i = 0; i < t_blob->
size(); i++) dst[i] = srcPtr[i];
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
A header file that provides wrapper classes for IExecutableNetwork.
void TopResults(unsigned int n, TBlob< T > &input, std::vector< unsigned > &output)
Gets the top n results from a tblob.
Definition: inference_engine.hpp:48
A header file that provides versioning information for the inference engine shared library...
A header file for a plugin logging mechanism.
std::vector< int > offset
A vector of offsets for each dimension.
Definition: ie_layers.h:1256
This is a header file for the Network reader class (wrapper) used to build networks from a given IR...
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
void ConvertImageToInput(unsigned char *imgBufRGB8, size_t lengthbytesSize, Blob &input)
Splits the RGB channels to either I16 Blob or float blob.
Definition: inference_engine.hpp:176
std::string name
Layer name.
Definition: ie_layers.h:42
void copyToFloat(float *dst, const InferenceEngine::Blob *src)
Copies data from a certain precision to float.
Definition: inference_engine.hpp:199
A header file for Blob and generic TBlob<>
void copyFromRGB8(uint8_t *RGB8, size_t RGB8_size, InferenceEngine::TBlob< data_t > *blob)
Copies a 8-bit RGB image to the blob.
Definition: inference_engine.hpp:128
A header for a class to handle plugin loading.
This is a header file for the ICNNNetwork class.
Represents real host memory allocated for a Tensor/Blob per C type.
Definition: ie_blob.h:470
virtual LockedMemory< const T > readOnly() const noexcept
Creates a new empty rvalue read-only LockedMemory object.
Definition: ie_blob.h:587
size_t size() const noexcept override
Returns the total number of elements, which is a product of all the dimensions.
Definition: ie_blob.h:312
This is a header file for the Inference Engine Core class C++ API.
a header file for internal Layers structure to describe layers information
a header for advanced hardware related properties for IE plugins
This is a header file for the ICNNNetworkStats class.
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
This class represents a universal container in the Inference Engine.
Definition: ie_blob.h:37
std::vector< size_t > SizeVector
Represents tensor size.
Definition: ie_common.h:29
This is a header file for the Inference Engine plugin C++ API.