Jetson Inference
DNN Vision Library

Action/activity recognition DNN. More...

Classes

class  actionNet
 Action/activity classification on a sequence of images or video, using TensorRT. More...
 

Macros

#define ACTIONNET_DEFAULT_INPUT   "input"
 Name of default input blob for actionNet model. More...
 
#define ACTIONNET_DEFAULT_OUTPUT   "output"
 Name of default output confidence values for actionNet model. More...
 
#define ACTIONNET_MODEL_TYPE   "action"
 The model type for actionNet in data/networks/models.json. More...
 
#define ACTIONNET_USAGE_STRING
 Standard command-line options able to be passed to actionNet::Create() More...
 

Detailed Description

Action/activity recognition DNN.


Class Documentation

◆ actionNet

class actionNet

Action/activity classification on a sequence of images or video, using TensorRT.

Inheritance diagram for actionNet:
tensorNet

Public Member Functions

virtual ~actionNet ()
 Destroy. More...
 
template<typename T >
int Classify (T *image, uint32_t width, uint32_t height, float *confidence=NULL)
 Append an image to the sequence and classify the action, returning the index of the top class. More...
 
int Classify (void *image, uint32_t width, uint32_t height, imageFormat format, float *confidence=NULL)
 Append an image to the sequence and classify the action, returning the index of the top class. More...
 
uint32_t GetNumClasses () const
 Retrieve the number of image recognition classes. More...
 
const char * GetClassLabel (int index) const
 Retrieve the description of a particular class. More...
 
const char * GetClassDesc (int index) const
 Retrieve the description of a particular class. More...
 
const char * GetClassPath () const
 Retrieve the path to the file containing the class descriptions. More...
 
float GetThreshold () const
 Return the confidence threshold used for classification. More...
 
void SetThreshold (float threshold)
 Set the confidence threshold used for classification. More...
 
uint32_t GetSkipFrames () const
 Return the number of frames that are skipped in between classifications. More...
 
void SetSkipFrames (uint32_t frames)
 Set the number of frames that are skipped in between classifications. More...
 
- Public Member Functions inherited from tensorNet
virtual ~tensorNet ()
 Destory. More...
 
bool LoadNetwork (const char *prototxt, const char *model, const char *mean=NULL, const char *input_blob="data", const char *output_blob="prob", uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true, nvinfer1::IInt8Calibrator *calibrator=NULL, cudaStream_t stream=NULL)
 Load a new network instance. More...
 
bool LoadNetwork (const char *prototxt, const char *model, const char *mean, const char *input_blob, const std::vector< std::string > &output_blobs, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true, nvinfer1::IInt8Calibrator *calibrator=NULL, cudaStream_t stream=NULL)
 Load a new network instance with multiple output layers. More...
 
bool LoadNetwork (const char *prototxt, const char *model, const char *mean, const std::vector< std::string > &input_blobs, const std::vector< std::string > &output_blobs, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true, nvinfer1::IInt8Calibrator *calibrator=NULL, cudaStream_t stream=NULL)
 Load a new network instance with multiple input layers. More...
 
bool LoadNetwork (const char *prototxt, const char *model, const char *mean, const char *input_blob, const Dims3 &input_dims, const std::vector< std::string > &output_blobs, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true, nvinfer1::IInt8Calibrator *calibrator=NULL, cudaStream_t stream=NULL)
 Load a new network instance (this variant is used for UFF models) More...
 
bool LoadNetwork (const char *prototxt, const char *model, const char *mean, const std::vector< std::string > &input_blobs, const std::vector< Dims3 > &input_dims, const std::vector< std::string > &output_blobs, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true, nvinfer1::IInt8Calibrator *calibrator=NULL, cudaStream_t stream=NULL)
 Load a new network instance with multiple input layers (used for UFF models) More...
 
bool LoadEngine (const char *engine_filename, const std::vector< std::string > &input_blobs, const std::vector< std::string > &output_blobs, nvinfer1::IPluginFactory *pluginFactory=NULL, deviceType device=DEVICE_GPU, cudaStream_t stream=NULL)
 Load a network instance from a serialized engine plan file. More...
 
bool LoadEngine (char *engine_stream, size_t engine_size, const std::vector< std::string > &input_blobs, const std::vector< std::string > &output_blobs, nvinfer1::IPluginFactory *pluginFactory=NULL, deviceType device=DEVICE_GPU, cudaStream_t stream=NULL)
 Load a network instance from a serialized engine plan file. More...
 
bool LoadEngine (nvinfer1::ICudaEngine *engine, const std::vector< std::string > &input_blobs, const std::vector< std::string > &output_blobs, deviceType device=DEVICE_GPU, cudaStream_t stream=NULL)
 Load network resources from an existing TensorRT engine instance. More...
 
bool LoadEngine (const char *filename, char **stream, size_t *size)
 Load a serialized engine plan file into memory. More...
 
void EnableLayerProfiler ()
 Manually enable layer profiling times. More...
 
void EnableDebug ()
 Manually enable debug messages and synchronization. More...
 
bool AllowGPUFallback () const
 Return true if GPU fallback is enabled. More...
 
deviceType GetDevice () const
 Retrieve the device being used for execution. More...
 
precisionType GetPrecision () const
 Retrieve the type of precision being used. More...
 
bool IsPrecision (precisionType type) const
 Check if a particular precision is being used. More...
 
cudaStream_t GetStream () const
 Retrieve the stream that the device is operating on. More...
 
cudaStream_t CreateStream (bool nonBlocking=true)
 Create and use a new stream for execution. More...
 
void SetStream (cudaStream_t stream)
 Set the stream that the device is operating on. More...
 
const char * GetPrototxtPath () const
 Retrieve the path to the network prototxt file. More...
 
const char * GetModelPath () const
 Retrieve the full path to model file, including the filename. More...
 
const char * GetModelFilename () const
 Retrieve the filename of the file, excluding the directory. More...
 
modelType GetModelType () const
 Retrieve the format of the network model. More...
 
bool IsModelType (modelType type) const
 Return true if the model is of the specified format. More...
 
uint32_t GetInputLayers () const
 Retrieve the number of input layers to the network. More...
 
uint32_t GetOutputLayers () const
 Retrieve the number of output layers to the network. More...
 
Dims3 GetInputDims (uint32_t layer=0) const
 Retrieve the dimensions of network input layer. More...
 
uint32_t GetInputWidth (uint32_t layer=0) const
 Retrieve the width of network input layer. More...
 
uint32_t GetInputHeight (uint32_t layer=0) const
 Retrieve the height of network input layer. More...
 
uint32_t GetInputSize (uint32_t layer=0) const
 Retrieve the size (in bytes) of network input layer. More...
 
float * GetInputPtr (uint32_t layer=0) const
 Get the CUDA pointer to the input layer's memory. More...
 
Dims3 GetOutputDims (uint32_t layer=0) const
 Retrieve the dimensions of network output layer. More...
 
uint32_t GetOutputWidth (uint32_t layer=0) const
 Retrieve the width of network output layer. More...
 
uint32_t GetOutputHeight (uint32_t layer=0) const
 Retrieve the height of network output layer. More...
 
uint32_t GetOutputSize (uint32_t layer=0) const
 Retrieve the size (in bytes) of network output layer. More...
 
float * GetOutputPtr (uint32_t layer=0) const
 Get the CUDA pointer to the output memory. More...
 
float GetNetworkFPS ()
 Retrieve the network frames per second (FPS). More...
 
float GetNetworkTime ()
 Retrieve the network runtime (in milliseconds). More...
 
const char * GetNetworkName () const
 Retrieve the network name (it's filename). More...
 
float2 GetProfilerTime (profilerQuery query)
 Retrieve the profiler runtime (in milliseconds). More...
 
float GetProfilerTime (profilerQuery query, profilerDevice device)
 Retrieve the profiler runtime (in milliseconds). More...
 
void PrintProfilerTimes ()
 Print the profiler times (in millseconds). More...
 

Static Public Member Functions

static actionNetCreate (const char *network="resnet-18", uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true)
 Load a pre-trained model, either "resnet-18" or "resnet-34". More...
 
static actionNetCreate (const char *model_path, const char *class_labels, const char *input=ACTIONNET_DEFAULT_INPUT, const char *output=ACTIONNET_DEFAULT_OUTPUT, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true)
 Load a new network instance. More...
 
static actionNetCreate (int argc, char **argv)
 Load a new network instance by parsing the command line. More...
 
static actionNetCreate (const commandLine &cmdLine)
 Load a new network instance by parsing the command line. More...
 
static const char * Usage ()
 Usage string for command line arguments to Create() More...
 
- Static Public Member Functions inherited from tensorNet
static bool LoadClassLabels (const char *filename, std::vector< std::string > &descriptions, int expectedClasses=-1)
 Load class descriptions from a label file. More...
 
static bool LoadClassLabels (const char *filename, std::vector< std::string > &descriptions, std::vector< std::string > &synsets, int expectedClasses=-1)
 Load class descriptions and synset strings from a label file. More...
 
static bool LoadClassColors (const char *filename, float4 *colors, int expectedClasses, float defaultAlpha=255.0f)
 Load class colors from a text file. More...
 
static bool LoadClassColors (const char *filename, float4 **colors, int expectedClasses, float defaultAlpha=255.0f)
 Load class colors from a text file. More...
 
static float4 GenerateColor (uint32_t classID, float alpha=255.0f)
 Procedurally generate a color for a given class index with the specified alpha value. More...
 
static precisionType SelectPrecision (precisionType precision, deviceType device=DEVICE_GPU, bool allowInt8=true)
 Resolve a desired precision to a specific one that's available. More...
 
static precisionType FindFastestPrecision (deviceType device=DEVICE_GPU, bool allowInt8=true)
 Determine the fastest native precision on a device. More...
 
static std::vector< precisionTypeDetectNativePrecisions (deviceType device=DEVICE_GPU)
 Detect the precisions supported natively on a device. More...
 
static bool DetectNativePrecision (const std::vector< precisionType > &nativeTypes, precisionType type)
 Detect if a particular precision is supported natively. More...
 
static bool DetectNativePrecision (precisionType precision, deviceType device=DEVICE_GPU)
 Detect if a particular precision is supported natively. More...
 

Protected Member Functions

 actionNet ()
 
bool init (const char *model_path, const char *class_path, const char *input, const char *output, uint32_t maxBatchSize, precisionType precision, deviceType device, bool allowGPUFallback)
 
bool preProcess (void *image, uint32_t width, uint32_t height, imageFormat format)
 
- Protected Member Functions inherited from tensorNet
 tensorNet ()
 Constructor. More...
 
bool ProcessNetwork (bool sync=true)
 Execute processing of the network. More...
 
bool ProfileModel (const std::string &deployFile, const std::string &modelFile, const std::vector< std::string > &inputs, const std::vector< Dims3 > &inputDims, const std::vector< std::string > &outputs, uint32_t maxBatchSize, precisionType precision, deviceType device, bool allowGPUFallback, nvinfer1::IInt8Calibrator *calibrator, char **engineStream, size_t *engineSize)
 Create and output an optimized network model. More...
 
bool ConfigureBuilder (nvinfer1::IBuilder *builder, uint32_t maxBatchSize, uint32_t workspaceSize, precisionType precision, deviceType device, bool allowGPUFallback, nvinfer1::IInt8Calibrator *calibrator)
 Configure builder options. More...
 
bool ValidateEngine (const char *model_path, const char *cache_path, const char *checksum_path)
 Validate that the model already has a built TensorRT engine that exists and doesn't need updating. More...
 
void PROFILER_BEGIN (profilerQuery query)
 Begin a profiling query, before network is run. More...
 
void PROFILER_END (profilerQuery query)
 End a profiling query, after the network is run. More...
 
bool PROFILER_QUERY (profilerQuery query)
 Query the CUDA part of a profiler query. More...
 

Protected Attributes

float * mInputBuffers [2]
 
uint32_t mNumClasses
 
uint32_t mNumFrames
 
uint32_t mSkipFrames
 
uint32_t mFramesSkipped
 
uint32_t mCurrentInputBuffer
 
uint32_t mCurrentFrameIndex
 
float mThreshold
 
float mLastConfidence
 
int mLastClassification
 
std::vector< std::string > mClassDesc
 
std::string mClassPath
 
- Protected Attributes inherited from tensorNet
tensorNet::Logger gLogger
 
tensorNet::Profiler gProfiler
 
std::string mPrototxtPath
 
std::string mModelPath
 
std::string mModelFile
 
std::string mMeanPath
 
std::string mCacheEnginePath
 
std::string mCacheCalibrationPath
 
std::string mChecksumPath
 
deviceType mDevice
 
precisionType mPrecision
 
modelType mModelType
 
cudaStream_t mStream
 
cudaEvent_t mEventsGPU [PROFILER_TOTAL *2]
 
timespec mEventsCPU [PROFILER_TOTAL *2]
 
nvinfer1::IRuntime * mInfer
 
nvinfer1::ICudaEngine * mEngine
 
nvinfer1::IExecutionContext * mContext
 
float2 mProfilerTimes [PROFILER_TOTAL+1]
 
uint32_t mProfilerQueriesUsed
 
uint32_t mProfilerQueriesDone
 
uint32_t mWorkspaceSize
 
uint32_t mMaxBatchSize
 
bool mEnableProfiler
 
bool mEnableDebug
 
bool mAllowGPUFallback
 
void ** mBindings
 
std::vector< layerInfomInputs
 
std::vector< layerInfomOutputs
 

Constructor & Destructor Documentation

◆ ~actionNet()

virtual actionNet::~actionNet ( )
virtual

Destroy.

◆ actionNet()

actionNet::actionNet ( )
protected

Member Function Documentation

◆ Classify() [1/2]

template<typename T >
int actionNet::Classify ( T *  image,
uint32_t  width,
uint32_t  height,
float *  confidence = NULL 
)
inline

Append an image to the sequence and classify the action, returning the index of the top class.

Either the class with the maximum confidence will be returned, or -1 if no class meets the threshold set by SetThreshold() or the --threshold command-line argument.

If this frame was skipped due to SetSkipFrames() being used, then the last frame's results will be returned. By default, every other frame is skipped in order to lengthen the action's window.

Parameters
imageinput image in CUDA device memory.
widthwidth of the input image in pixels.
heightheight of the input image in pixels.
confidenceoptional pointer to float filled with confidence value.
Returns
Index of the maximum likelihood class, or -1 on error.

◆ Classify() [2/2]

int actionNet::Classify ( void *  image,
uint32_t  width,
uint32_t  height,
imageFormat  format,
float *  confidence = NULL 
)

Append an image to the sequence and classify the action, returning the index of the top class.

Either the class with the maximum confidence will be returned, or -1 if no class meets the threshold set by SetThreshold() or the --threshold command-line argument.

If this frame was skipped due to SetSkipFrames() being used, then the last frame's results will be returned. By default, every other frame is skipped in order to lengthen the action's window.

Parameters
imageinput image in CUDA device memory.
widthwidth of the input image in pixels.
heightheight of the input image in pixels.
confidenceoptional pointer to float filled with confidence value.
Returns
Index of the maximum likelihood class, or -1 on error.

◆ Create() [1/4]

static actionNet* actionNet::Create ( const char *  model_path,
const char *  class_labels,
const char *  input = ACTIONNET_DEFAULT_INPUT,
const char *  output = ACTIONNET_DEFAULT_OUTPUT,
uint32_t  maxBatchSize = DEFAULT_MAX_BATCH_SIZE,
precisionType  precision = TYPE_FASTEST,
deviceType  device = DEVICE_GPU,
bool  allowGPUFallback = true 
)
static

Load a new network instance.

Parameters
prototxt_pathFile path to the deployable network prototxt
model_pathFile path to the caffemodel
mean_binaryFile path to the mean value binary proto (can be NULL)
class_labelsFile path to list of class name labels
inputName of the input layer blob.
outputName of the output layer blob.
maxBatchSizeThe maximum batch size that the network will support and be optimized for.

◆ Create() [2/4]

static actionNet* actionNet::Create ( const char *  network = "resnet-18",
uint32_t  maxBatchSize = DEFAULT_MAX_BATCH_SIZE,
precisionType  precision = TYPE_FASTEST,
deviceType  device = DEVICE_GPU,
bool  allowGPUFallback = true 
)
static

Load a pre-trained model, either "resnet-18" or "resnet-34".

◆ Create() [3/4]

static actionNet* actionNet::Create ( const commandLine cmdLine)
static

Load a new network instance by parsing the command line.

◆ Create() [4/4]

static actionNet* actionNet::Create ( int  argc,
char **  argv 
)
static

Load a new network instance by parsing the command line.

◆ GetClassDesc()

const char* actionNet::GetClassDesc ( int  index) const
inline

Retrieve the description of a particular class.

◆ GetClassLabel()

const char* actionNet::GetClassLabel ( int  index) const
inline

Retrieve the description of a particular class.

◆ GetClassPath()

const char* actionNet::GetClassPath ( ) const
inline

Retrieve the path to the file containing the class descriptions.

◆ GetNumClasses()

uint32_t actionNet::GetNumClasses ( ) const
inline

Retrieve the number of image recognition classes.

◆ GetSkipFrames()

uint32_t actionNet::GetSkipFrames ( ) const
inline

Return the number of frames that are skipped in between classifications.

See also
SetFrameSkip for more info.

◆ GetThreshold()

float actionNet::GetThreshold ( ) const
inline

Return the confidence threshold used for classification.

◆ init()

bool actionNet::init ( const char *  model_path,
const char *  class_path,
const char *  input,
const char *  output,
uint32_t  maxBatchSize,
precisionType  precision,
deviceType  device,
bool  allowGPUFallback 
)
protected

◆ preProcess()

bool actionNet::preProcess ( void *  image,
uint32_t  width,
uint32_t  height,
imageFormat  format 
)
protected

◆ SetSkipFrames()

void actionNet::SetSkipFrames ( uint32_t  frames)
inline

Set the number of frames that are skipped in between classifications.

Since actionNet operates on video sequences, it's often helpful to skip frames to lengthen the window of time the model gets to 'see' an action being performed.

The default setting is 1, where every other frame is skipped. Setting this to 0 will disable it, and every frame will be processed. When a frame is skipped, the classification results from the last frame are returned.

◆ SetThreshold()

void actionNet::SetThreshold ( float  threshold)
inline

Set the confidence threshold used for classification.

Classes with a confidence below this threshold will be ignored.

Note
this can also be set using the --threshold=N command-line argument.

◆ Usage()

static const char* actionNet::Usage ( )
inlinestatic

Usage string for command line arguments to Create()

Member Data Documentation

◆ mClassDesc

std::vector<std::string> actionNet::mClassDesc
protected

◆ mClassPath

std::string actionNet::mClassPath
protected

◆ mCurrentFrameIndex

uint32_t actionNet::mCurrentFrameIndex
protected

◆ mCurrentInputBuffer

uint32_t actionNet::mCurrentInputBuffer
protected

◆ mFramesSkipped

uint32_t actionNet::mFramesSkipped
protected

◆ mInputBuffers

float* actionNet::mInputBuffers[2]
protected

◆ mLastClassification

int actionNet::mLastClassification
protected

◆ mLastConfidence

float actionNet::mLastConfidence
protected

◆ mNumClasses

uint32_t actionNet::mNumClasses
protected

◆ mNumFrames

uint32_t actionNet::mNumFrames
protected

◆ mSkipFrames

uint32_t actionNet::mSkipFrames
protected

◆ mThreshold

float actionNet::mThreshold
protected

Macro Definition Documentation

◆ ACTIONNET_DEFAULT_INPUT

#define ACTIONNET_DEFAULT_INPUT   "input"

Name of default input blob for actionNet model.

◆ ACTIONNET_DEFAULT_OUTPUT

#define ACTIONNET_DEFAULT_OUTPUT   "output"

Name of default output confidence values for actionNet model.

◆ ACTIONNET_MODEL_TYPE

#define ACTIONNET_MODEL_TYPE   "action"

The model type for actionNet in data/networks/models.json.

◆ ACTIONNET_USAGE_STRING

#define ACTIONNET_USAGE_STRING
Value:
"actionNet arguments: \n" \
" --network=NETWORK pre-trained model to load, one of the following:\n" \
" * resnet-18 (default)\n" \
" * resnet-34\n" \
" --model=MODEL path to custom model to load (.onnx)\n" \
" --labels=LABELS path to text file containing the labels for each class\n" \
" --input-blob=INPUT name of the input layer (default is '" ACTIONNET_DEFAULT_INPUT "')\n" \
" --output-blob=OUTPUT name of the output layer (default is '" ACTIONNET_DEFAULT_OUTPUT "')\n" \
" --threshold=CONF minimum confidence threshold for classification (default is 0.01)\n" \
" --skip-frames=SKIP how many frames to skip between classifications (default is 1)\n" \
" --profile enable layer profiling in TensorRT\n\n"

Standard command-line options able to be passed to actionNet::Create()

ACTIONNET_DEFAULT_INPUT
#define ACTIONNET_DEFAULT_INPUT
Name of default input blob for actionNet model.
Definition: actionNet.h:34
ACTIONNET_DEFAULT_OUTPUT
#define ACTIONNET_DEFAULT_OUTPUT
Name of default output confidence values for actionNet model.
Definition: actionNet.h:40