class InferenceEngine::Blob

Overview

This class represents a universal container in the Inference Engine. More…

#include <ie_blob.h>

class Blob
{
public:
    // typedefs

    typedef std::shared_ptr<Blob> Ptr;
    typedef std::shared_ptr<const Blob> CPtr;

    // construction

    Blob(const TensorDesc& tensorDesc);

    // methods

    static Ptr CreateFromData(const DataPtr& data);

    template <
        typename T,
        typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
        typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
        >
    bool is();

    template <
        typename T,
        typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
        typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
        >
    bool is() const;

    template <
        typename T,
        typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
        typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
        >
    T \* as();

    template <
        typename T,
        typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
        typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
        >
    const T \* as() const;

    virtual const TensorDesc& getTensorDesc() const;
    virtual TensorDesc& getTensorDesc();
    virtual size_t size() const;
    virtual size_t byteSize() const;
    virtual size_t element_size() const = 0;
    virtual void allocate() = 0;
    virtual bool deallocate() = 0;
    void setShape(const SizeVector& dims);
    virtual Blob::Ptr createROI(const ROI& roi) const;

    virtual Blob::Ptr createROI(
        const std::vector<std::size_t>& begin,
        const std::vector<std::size_t>& end
        ) const;
};

// direct descendants

class CompoundBlob;
class MemoryBlob;

Detailed Documentation

This class represents a universal container in the Inference Engine.

Each Blob implementation must be derived from this Blob class directly or indirectly

Typedefs

typedef std::shared_ptr<Blob> Ptr

A smart pointer containing Blob object.

typedef std::shared_ptr<const Blob> CPtr

A smart pointer to the const Blob object.

Construction

Blob(const TensorDesc& tensorDesc)

Constructor. Creates an empty Blob object with the specified precision.

Parameters:

tensorDesc

Defines the layout and dims of the blob

Methods

static Ptr CreateFromData(const DataPtr& data)

Creates a TBlob<> object from a Data node.

Parameters:

data

A reference to a smart pointer of the Data node

Returns:

Smart pointer to TBlob<> with the relevant C type to the precision of the data node

template <
    typename T,
    typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
    typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
    >
bool is()

Checks if the Blob object can be cast to the type T*.

Parameters:

T

Type to be checked. Must represent a class derived from the Blob

Returns:

true if this object can be dynamically cast to the type T*. Otherwise, false

template <
    typename T,
    typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
    typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
    >
bool is() const

Checks if the Blob object can be cast to the type const T*.

Parameters:

T

Type to be checked. Must represent a class derived from the Blob

Returns:

true if this object can be dynamically cast to the type const T*. Otherwise, false

template <
    typename T,
    typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
    typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
    >
T \* as()

Casts this Blob object to the type T*.

Use InferenceEngine::as() to operate with shared Blob objects instead of raw pointers

Parameters:

T

Type to cast to. Must represent a class derived from the Blob

Returns:

Raw pointer to the object of the type T or nullptr on error

template <
    typename T,
    typename std::enable_if<!std::is_pointer<T>::value&&!std::is_reference<T>::value, int>::type = 0,
    typename std::enable_if<std::is_base_of<Blob, T>::value, int>::type = 0
    >
const T \* as() const

Casts this Blob object to the type const T*.

Use InferenceEngine::as() to operate with shared Blob objects instead of raw pointers

Parameters:

T

Type to cast to. Must represent a class derived from the Blob

Returns:

Raw pointer to the object of the type const T or nullptr on error

virtual const TensorDesc& getTensorDesc() const

Returns the tensor description.

Returns:

A const reference to a tensor descriptor

virtual TensorDesc& getTensorDesc()

Returns the tensor description.

Returns:

A reference to a tensor descriptor

virtual size_t size() const

By default, returns the total number of elements (a product of all the dims or 1 for scalar)

Return value and its interpretation heavily depend on the blob type

Returns:

The total number of elements

virtual size_t byteSize() const

Returns the size of the current Blob in bytes.

Returns:

Blob ‘s size in bytes

virtual size_t element_size() const = 0

Provides the number of bytes per element.

Deprecated Cast to MemoryBlob and use its API instead. Blob class can represent compound blob, which do not refer to the only solid memory.

The overall Blob capacity is size() * element_size(). Abstract method.

Returns:

Returns the number of bytes per element

virtual void allocate() = 0

Allocates memory to store the data.

Abstract method.

virtual bool deallocate() = 0

Releases previously allocated data.

Abstract method.

Returns:

True if deallocation happens successfully, false otherwise.

void setShape(const SizeVector& dims)

Set new shape for blob, deallocate/allocate if new total size is bigger than previous one.

Parameters:

dims

new shape

virtual Blob::Ptr createROI(const ROI& roi) const

Creates a blob describing given ROI object based on the current blob with memory sharing.

Note: default implementation throws “not implemented” exception.

Parameters:

roi

A ROI object inside of the current blob.

Returns:

A shared pointer to the newly created ROI blob.

virtual Blob::Ptr createROI(
    const std::vector<std::size_t>& begin,
    const std::vector<std::size_t>& end
    ) const

Creates a blob describing given ROI object based on the current blob with memory sharing.

Note: default implementation may throws “not implemented” exception.

Parameters:

begin

A ROI start coordinate

end

A ROI end coordinate

Returns:

A shared pointer to the newly created ROI blob.