InferenceEngine::Blob
is the main class intended for working with memory. Using this class you can read and write memory, get information about the memory structure etc.
The right way to create Blob
objects with a specific layout is to use constructors with InferenceEngine::TensorDesc
.
InferenceEngige::TensorDesc tdesc(FP32, {1, 3, 227, 227}, InferenceEngine::Layout::NCHW); InferenceEngine::Blob::Ptr blob = InferenceEngine::make_shared_blob<float>(tdesc);
InferenceEngine::TensorDesc
is a special class that provides layout format description.
This class allows to create planar layouts using the standard formats (like InferenceEngine::Layout::NCDHW
, InferenceEngine::Layout::NCHW
, InferenceEngine::Layout::NC
, InferenceEngine::Layout::C
and etc) and also non-planar layouts using InferenceEngine::BlockingDesc
.
In order to create a complex layout you should use InferenceEngine::BlockingDesc
which allows to define the blocked memory with offsets and strides.
InferenceEngine::BlockingDesc({1, 20, 20, 25}, {0, 2, 3, 1}); // or InferenceEngine::BlockingDesc({1, 20, 20, 25}, InferenceEngine::Layout::NHWC);
InferenceEngine::BlockingDesc({1, 4, 20, 20, 8}, {0, 1, 2, 3, 1})
InferenceEngine::TensorDesc::offset(size_t l)
or InferenceEngine::TensorDesc::offset(SizeVector v)
.InferenceEngine::BlockingDesc blk({1, 4, 20, 20, 8}, {0, 1, 2, 3, 1}); InferenceEngine::TensorDesc tdesc(FP32, {1, 25, 20, 20}, blk); tdesc.offset(0); // = 0 tdesc.offset(1); // = 8 tdesc.offset({0, 0, 0, 2}); // = 16 tdesc.offset({0, 1, 0, 2}); // = 17
InferenceEngine::TensorDesc::getLayoutByDims
. InferenceEngine::TensorDesc::getLayoutByDims({1}); // InferenceEngine::Layout::C InferenceEngine::TensorDesc::getLayoutByDims({1, 2}); // InferenceEngine::Layout::NC InferenceEngine::TensorDesc::getLayoutByDims({1, 2, 3, 4}); // InferenceEngine::Layout::NCHW InferenceEngine::TensorDesc::getLayoutByDims({1, 2, 3}); // InferenceEngine::Layout::BLOCKED InferenceEngine::TensorDesc::getLayoutByDims({1, 2, 3, 4, 5}); // InferenceEngine::Layout::NCDHW InferenceEngine::TensorDesc::getLayoutByDims({1, 2, 3, 4, 5, ...}); // InferenceEngine::Layout::BLOCKED