class gstgva::tensor::Tensor#

Overview#

This class represents tensor - map-like storage for inference result information, such as output blob description (output layer dims, layout, rank, precision, etc.), inference result in a raw and interpreted forms. More…

class Tensor {
public:
    // classes

    class LAYOUT;
    class PRECISION;

    // methods

    List[int] dims(self self);
    PRECISION precision(self self);
    LAYOUT layout(self self);
    numpy.ndarray data(self self);
    str name(self self);
    str model_name(self self);
    str layer_name(self self);
    float confidence(self self);
    str label(self self);
    int object_id(self self);
    str format(self self);
    List[str] fields(self self);
    def __getitem__(self self, key key);
    int __len__(self self);
    def __iter__(self self);
    str __repr__(self self);
    None __delitem__(self self, str key);
    int label_id(self self);
    str element_id(self self);
    None set_name(self self, str name);
    str layout_as_string(self self);
    str precision_as_string(self self);
    None set_label(self self, str label);
    bool has_field(self self, str field_name);
    bool is_detection(self self);
    def __init__(self self, ctypes.c_void_p structure);
    None __setitem__(self self, str key, item item);
};

Detailed Documentation#

This class represents tensor - map-like storage for inference result information, such as output blob description (output layer dims, layout, rank, precision, etc.), inference result in a raw and interpreted forms.

Tensor is based on GstStructure and, in general, can contain arbitrary (user-defined) fields of simplest data types, like integers, floats & strings. Tensor can contain only raw inference result (such Tensor is produced by gvainference in Gstreamer pipeline), detection result (such Tensor is produced by gvadetect in Gstreamer pipeline and it’s called detection Tensor), or both raw & interpreted inference results (such Tensor is produced by gvaclassify in Gstreamer pipeline). Tensors can be created and used on their own, or they can be created within RegionOfInterest or VideoFrame instances. Usually, in Gstreamer pipeline with GVA elements (gvadetect, gvainference, gvaclassify) Tensor objects will be available for access and modification from RegionOfInterest and VideoFrame instances

Methods#

List[int] dims(self self)

Get inference result blob dimensions info.

Returns:

list of dimensions

PRECISION precision(self self)

Get inference results blob precision.

Returns:

PRECISION, PRECISION.UNSPECIFIED if can’t be read

LAYOUT layout(self self)

Get inference result blob layout.

Returns:

LAYOUT, LAYOUT.ANY if can’t be read

numpy.ndarray data(self self)

Get raw inference result blob data.

Returns:

numpy.ndarray of values representing raw inference data, None if data can’t be read

str name(self self)

Get name as a string.

Returns:

Tensor instance’s name

str model_name(self self)

Get model name which was used for inference.

Returns:

model name as a string, None if failed to get

str layer_name(self self)

Get inference result blob layer name.

Returns:

layer name as a string, None if failed to get

float confidence(self self)

Get confidence of inference result.

Returns:

confidence of inference result as a float, None if failed to get

str label(self self)

Get label.

This label is set for Tensor instances produced by gvaclassify element. It will raise exception if called for detection Tensor. To get detection class label, use RegionOfInterest.label

Returns:

label as a string, None if failed to get

int object_id(self self)

Get object id.

Returns:

object id as an int, None if failed to get

str format(self self)

Get format.

Returns:

format as a string, None if failed to get

List[str] fields(self self)

Get list of fields contained in Tensor instance.

Returns:

List of fields contained in Tensor instance

def __getitem__(self self, key key)

Get item by the field name.

Parameters:

key

Field name

Returns:

Item, None if failed to get

int __len__(self self)

Get number of fields contained in Tensor instance.

Returns:

Number of fields contained in Tensor instance

def __iter__(self self)

Iterable by all Tensor fields.

Returns:

Generator for all Tensor fields

str __repr__(self self)

Return string represenation of the Tensor instance.

Returns:

String of field names and values

None __delitem__(self self, str key)

Remove item by the field name.

Parameters:

key

Field name

int label_id(self self)

Get label id.

Returns:

label id as an int, None if failed to get

str element_id(self self)

Get inference-id property value of GVA element from which this Tensor came.

Returns:

inference-id property value of GVA element from which this Tensor came, None if failed to get

None set_name(self self, str name)

Set Tensor instance’s name.

str layout_as_string(self self)

Get inference result blob layout as a string.

Returns:

layout as a string, “ANY” if can’t be read

str precision_as_string(self self)

Get inference results blob precision as a string.

Returns:

precision as a string, “UNSPECIFIED” if can’t be read

None set_label(self self, str label)

Set label.

It will raise exception if called for detection Tensor

Parameters:

label

label name as a string

bool has_field(self self, str field_name)

Check if Tensor instance has field.

Parameters:

field_name

field name

Returns:

True if field with this name is found, False otherwise

bool is_detection(self self)

Check if this Tensor is detection Tensor (contains detection results)

Returns:

True if tensor contains detection results, False otherwise

def __init__(self self, ctypes.c_void_p structure)

Construct Tensor instance from C-style GstStructure.

Parameters:

structure

C-style pointer to GstStructure to create Tensor instance from. There are much simpler ways for creating and obtaining Tensor instances - see RegionOfInterest and VideoFrame classes

None __setitem__(self self, str key, item item)

Set item to Tensor.

It can be one of the following types: string, int, float.

Parameters:

key

Name of new field

item

Item