GStreamer Video Analytics (GVA) Plugin
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
GVA::Tensor Class Reference

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 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. More...

#include <tensor.h>

Public Types

enum  Precision { Precision::UNSPECIFIED = GVA_PRECISION_UNSPECIFIED, Precision::FP32 = GVA_PRECISION_FP32, Precision::U8 = GVA_PRECISION_U8 }
 Describes tensor precision. More...
 
enum  Layout { Layout::ANY = GVA_LAYOUT_ANY, Layout::NCHW = GVA_LAYOUT_NCHW, Layout::NHWC = GVA_LAYOUT_NHWC, Layout::NC = GVA_LAYOUT_NC }
 Describes tensor layout. More...
 

Public Member Functions

template<class T >
const std::vector< T > data () const
 Get raw inference output blob data. More...
 
std::vector< guint > dims () const
 Get inference result blob dimensions info. More...
 
Precision precision () const
 Get inference output blob precision. More...
 
Layout layout () const
 Get inference result blob layout. More...
 
std::string layer_name () const
 Get inference result blob layer name. More...
 
std::string model_name () const
 Get model name which was used for inference. More...
 
std::string format () const
 Get data format as specified in model pre/post-processing json configuration. More...
 
std::string name () const
 Get tensor name as a string. More...
 
double confidence () const
 Get confidence of detection or classification result extracted from the tensor. More...
 
std::string label () const
 Get label. This label is set for Tensor instances produced by gvaclassify element. It will throw an exception if called for detection Tensor. To get detection class label, use RegionOfInterest::label. More...
 
std::vector< std::string > fields () const
 Get vector of fields contained in Tensor instance. More...
 
bool has_field (const std::string &field_name) const
 Check if Tensor instance has field. More...
 
std::string get_string (const std::string &field_name, const std::string &default_value=std::string()) const
 Get string contained in value stored at field_name. More...
 
int get_int (const std::string &field_name, int32_t default_value=0) const
 Get int contained in value stored at field_name. More...
 
double get_double (const std::string &field_name, double default_value=0) const
 Get double contained in value stored at field_name. More...
 
void set_string (const std::string &field_name, const std::string &value)
 Set field_name with string value. More...
 
void set_int (const std::string &field_name, int value)
 Set field_name with int value. More...
 
void set_double (const std::string &field_name, double value)
 Set field_name with double value. More...
 
void set_name (const std::string &name)
 Set Tensor instance's name.
 
void set_label (const std::string &label)
 Set label. It will throw an exception if called for detection Tensor. More...
 
std::string precision_as_string () const
 Get inference result blob precision as a string. More...
 
std::string layout_as_string () const
 Get inference result blob layout as a string. More...
 
std::string element_id () const
 Get inference-id property value of GVA element from which this Tensor came. More...
 
int label_id () const
 Get label id. More...
 
bool is_detection () const
 Check if this Tensor is detection Tensor (contains detection results) More...
 
 Tensor (GstStructure *structure)
 Construct Tensor instance from GstStructure. Tensor does not own structure, so if you use this consrtuctor, free structure after Tensor's lifetime, if needed. More...
 
GstStructure * gst_structure () const
 Get ptr to underlying GstStructure. More...
 

Protected Attributes

GstStructure * _structure
 ptr to GstStructure that contains all tensor (inference results) data & info.
 

Friends

class VideoFrame
 
class AudioFrame
 

Detailed Description

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 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.

Member Enumeration Documentation

◆ Layout

enum GVA::Tensor::Layout
strong

Describes tensor layout.

Enumerator
ANY 

unspecified layout

NCHW 

NCWH layout

NHWC 

NHWC layout

NC 

NC layout

◆ Precision

Describes tensor precision.

Enumerator
UNSPECIFIED 

default value

FP32 

32bit floating point value

U8 

unsignned 8bit integer value

Constructor & Destructor Documentation

◆ Tensor()

GVA::Tensor::Tensor ( GstStructure *  structure)
inline

Construct Tensor instance from GstStructure. Tensor does not own structure, so if you use this consrtuctor, free structure after Tensor's lifetime, if needed.

Parameters
structureGstStructure to create Tensor instance from.

Member Function Documentation

◆ confidence()

double GVA::Tensor::confidence ( ) const
inline

Get confidence of detection or classification result extracted from the tensor.

Returns
confidence of inference result as a double, 0 if failed to get

◆ data()

template<class T >
const std::vector<T> GVA::Tensor::data ( ) const
inline

Get raw inference output blob data.

Template Parameters
Ttype to interpret blob data
Returns
vector of values of type T representing raw inference data, empty vector if data can't be read

◆ dims()

std::vector<guint> GVA::Tensor::dims ( ) const
inline

Get inference result blob dimensions info.

Returns
vector of dimensions. Empty vector if dims are not set

◆ element_id()

std::string GVA::Tensor::element_id ( ) const
inline

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, empty string if failed to get

◆ fields()

std::vector<std::string> GVA::Tensor::fields ( ) const
inline

Get vector of fields contained in Tensor instance.

Returns
vector of fields contained in Tensor instance

◆ format()

std::string GVA::Tensor::format ( ) const
inline

Get data format as specified in model pre/post-processing json configuration.

Returns
format as a string, empty string if failed to get

◆ get_double()

double GVA::Tensor::get_double ( const std::string &  field_name,
double  default_value = 0 
) const
inline

Get double contained in value stored at field_name.

Parameters
field_namefield name
default_valuedefault value
Returns
double value stored at field_name if field_name is found and contains an double, default_value otherwise

◆ get_int()

int GVA::Tensor::get_int ( const std::string &  field_name,
int32_t  default_value = 0 
) const
inline

Get int contained in value stored at field_name.

Parameters
field_namefield name
default_valuedefault value
Returns
int value stored at field_name if field_name is found and contains an int, default_value otherwise

◆ get_string()

std::string GVA::Tensor::get_string ( const std::string &  field_name,
const std::string &  default_value = std::string() 
) const
inline

Get string contained in value stored at field_name.

Parameters
field_namefield name
default_valuedefault value
Returns
string value stored at field_name if field_name is found and contains a string, default_value string otherwise

◆ gst_structure()

GstStructure* GVA::Tensor::gst_structure ( ) const
inline

Get ptr to underlying GstStructure.

Returns
ptr to underlying GstStructure

◆ has_field()

bool GVA::Tensor::has_field ( const std::string &  field_name) const
inline

Check if Tensor instance has field.

Parameters
field_namefield name
Returns
True if field with this name is found, False otherwise

◆ is_detection()

bool GVA::Tensor::is_detection ( ) const
inline

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

Returns
True if tensor contains detection results, False otherwise

◆ label()

std::string GVA::Tensor::label ( ) const
inline

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

Returns
label as a string, empty string if failed to get

◆ label_id()

int GVA::Tensor::label_id ( ) const
inline

Get label id.

Returns
label id as an int, 0 if failed to get

◆ layer_name()

std::string GVA::Tensor::layer_name ( ) const
inline

Get inference result blob layer name.

Returns
layer name as a string, empty string if failed to get

◆ layout()

Layout GVA::Tensor::layout ( ) const
inline

Get inference result blob layout.

Returns
Enum Layout, Layout::ANY if can't be read

◆ layout_as_string()

std::string GVA::Tensor::layout_as_string ( ) const
inline

Get inference result blob layout as a string.

Returns
layout as a string, "ANY" if can't be read

◆ model_name()

std::string GVA::Tensor::model_name ( ) const
inline

Get model name which was used for inference.

Returns
model name as a string, empty string if failed to get

◆ name()

std::string GVA::Tensor::name ( ) const
inline

Get tensor name as a string.

Returns
Tensor instance's name

◆ precision()

Precision GVA::Tensor::precision ( ) const
inline

Get inference output blob precision.

Returns
Enum Precision, Precision::UNSPECIFIED if can't be read

◆ precision_as_string()

std::string GVA::Tensor::precision_as_string ( ) const
inline

Get inference result blob precision as a string.

Returns
precision as a string, "ANY" if can't be read

◆ set_double()

void GVA::Tensor::set_double ( const std::string &  field_name,
double  value 
)
inline

Set field_name with double value.

Parameters
field_namefield name
valuevalue to set

◆ set_int()

void GVA::Tensor::set_int ( const std::string &  field_name,
int  value 
)
inline

Set field_name with int value.

Parameters
field_namefield name
valuevalue to set

◆ set_label()

void GVA::Tensor::set_label ( const std::string &  label)
inline

Set label. It will throw an exception if called for detection Tensor.

Parameters
labellabel name as a string

◆ set_string()

void GVA::Tensor::set_string ( const std::string &  field_name,
const std::string &  value 
)
inline

Set field_name with string value.

Parameters
field_namefield name
valuevalue to set

The documentation for this class was generated from the following file: