44 size_t input_rank = dims.size();
45 if (!input_rank || !dims[0])
47 size_t batchSize = dims[0];
48 std::vector<unsigned> indexes(input.
size() / batchSize);
50 n =
static_cast<unsigned>(std::min<size_t>((size_t) n, input.
size()));
52 output.resize(n * batchSize);
54 for (
size_t i = 0; i < batchSize; i++) {
55 size_t offset = i * (input.
size() / batchSize);
56 T *batchData = input.
data();
59 std::iota(std::begin(indexes), std::end(indexes), 0);
60 std::partial_sort(std::begin(indexes), std::begin(indexes) + n, std::end(indexes),
61 [&batchData](
unsigned l,
unsigned r) {
62 return batchData[l] > batchData[r];
64 for (
unsigned j = 0; j < n; j++) {
65 output.at(i * n + j) = indexes.at(j);
70 #define TBLOB_TOP_RESULT(precision)\
71 case InferenceEngine::Precision::precision : {\
72 using myBlobType = InferenceEngine::PrecisionTrait<Precision::precision>::value_type;\
73 TBlob<myBlobType> &tblob = dynamic_cast<TBlob<myBlobType> &>(input);\
74 TopResults(n, tblob, output);\
84 inline void TopResults(
unsigned int n,
Blob &input, std::vector<unsigned> &output) {
86 TBLOB_TOP_RESULT(FP32);
87 TBLOB_TOP_RESULT(FP16);
88 TBLOB_TOP_RESULT(Q78);
89 TBLOB_TOP_RESULT(I16);
92 TBLOB_TOP_RESULT(U16);
93 TBLOB_TOP_RESULT(I32);
99 #undef TBLOB_TOP_RESULT
109 template<
typename data_t>
112 if (4 != dims.size())
113 THROW_IE_EXCEPTION <<
"Cannot write data to input blob! Blob has incorrect dimensions size "
115 size_t num_channels = dims[1];
116 size_t num_images = dims[0];
119 size_t nPixels = w * h;
121 if (RGB8_size != w * h * num_channels * num_images)
122 THROW_IE_EXCEPTION <<
"input pixels mismatch, expecting " << w * h * num_channels * num_images
123 <<
" bytes, got: " << RGB8_size;
125 std::vector<data_t *> dataArray;
126 for (
unsigned int n = 0; n < num_images; n++) {
127 for (
unsigned int i = 0; i < num_channels; i++) {
128 if (!n && !i && dataArray.empty()) {
129 dataArray.push_back(blob->
data());
131 dataArray.push_back(dataArray.at(n * num_channels + i - 1) + nPixels);
135 for (
size_t n = 0; n < num_images; n++) {
136 size_t n_num_channels = n * num_channels;
137 size_t n_num_channels_nPixels = n_num_channels * nPixels;
138 for (
size_t i = 0; i < nPixels; i++) {
139 size_t i_num_channels = i * num_channels + n_num_channels_nPixels;
140 for (
size_t j = 0; j < num_channels; j++) {
141 dataArray.at(n_num_channels + j)[i] = RGB8[i_num_channels + j];
156 if (float_input !=
nullptr)
copyFromRGB8(imgBufRGB8, lengthbytesSize, float_input);
159 if (short_input !=
nullptr)
copyFromRGB8(imgBufRGB8, lengthbytesSize, short_input);
162 if (byte_input !=
nullptr)
copyFromRGB8(imgBufRGB8, lengthbytesSize, byte_input);
176 if (t_blob ==
nullptr) {
180 const T *srcPtr = t_blob->
readOnly();
181 if (srcPtr ==
nullptr) {
184 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:22
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:42
A header file that provides versioning information for the inference engine shared library...
A header file for a plugin logging mechanism.
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:11
void ConvertImageToInput(unsigned char *imgBufRGB8, size_t lengthbytesSize, Blob &input)
Splits the RGB channels to either I16 Blob or float blob. The image buffer is assumed to be packed wi...
Definition: inference_engine.hpp:154
void copyToFloat(float *dst, const InferenceEngine::Blob *src)
Copies data from a certain precision to float.
Definition: inference_engine.hpp:171
virtual LockedMemory< T > data() noexcept
Creates an new empty rvalue LockedMemory object.
Definition: ie_blob.h:641
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. Throws an exception in case of dimensions or input size mismatc...
Definition: inference_engine.hpp:110
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:485
virtual LockedMemory< const T > readOnly() const noexcept
Creates a new empty rvalue read-only LockedMemory object.
Definition: ie_blob.h:649
size_t size() const noexcept override
Returns the total number of elements, which is a product of all the dimensions.
Definition: ie_blob.h:413
This is a header file for the Inference Engine Core class C++ API.
SizeVector & getDims()
Returns the vector of dimensions.
Definition: ie_layouts.h:191
a header file for internal Layers structure to describe layers information
a header for advanced hardware related properties for clDNN plugin To use in SetConfig() method of pl...
const TensorDesc & getTensorDesc() const noexcept override
Returns the tensor description.
Definition: ie_blob.h:399
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:35
virtual const TensorDesc & getTensorDesc() const noexcept
Returns the tensor description.
Definition: ie_blob.h:247
This header file contains aspects of working on different devices like CPU, GEN, FPGA, etc.
std::vector< size_t > SizeVector
Represents tensor size. The order is opposite to the order in Caffe*: (w,h,n,b) where the most freque...
Definition: ie_common.h:26
This is a header file for the Inference Engine plugin C++ API.
const Precision & getPrecision() const
Returns the memory precision.
Definition: ie_layouts.h:261