Jetson Inference
DNN Vision Library

Object recognition and localization networks with TensorRT support. More...

#include <detectNet.h>

Inheritance diagram for detectNet:
tensorNet

Classes

struct  Detection
 Object Detection result. More...
 

Public Types

enum  OverlayFlags { OVERLAY_NONE = 0, OVERLAY_BOX = (1 << 0), OVERLAY_LABEL = (1 << 1) }
 Overlay flags (can be OR'd together). More...
 
enum  NetworkType {
  CUSTOM = 0, COCO_AIRPLANE, COCO_BOTTLE, COCO_CHAIR,
  COCO_DOG, FACENET, PEDNET, PEDNET_MULTI
}
 Network choice enumeration. More...
 

Public Member Functions

virtual ~detectNet ()
 Destory. More...
 
int Detect (float *input, uint32_t width, uint32_t height, Detection **detections, uint32_t overlay=OVERLAY_BOX)
 Detect object locations from an RGBA image, returning an array containing the detection results. More...
 
int Detect (float *input, uint32_t width, uint32_t height, Detection *detections, uint32_t overlay=OVERLAY_BOX)
 Detect object locations in an RGBA image, into an array of the results allocated by the user. More...
 
bool Overlay (float *input, float *output, uint32_t width, uint32_t height, Detection *detections, uint32_t numDetections, uint32_t flags=OVERLAY_BOX)
 Draw the detected bounding boxes overlayed on an RGBA image. More...
 
float GetThreshold () const
 Retrieve the minimum threshold for detection. More...
 
void SetThreshold (float threshold)
 Set the minimum threshold for detection. More...
 
uint32_t GetMaxDetections () const
 Retrieve the maximum number of simultaneous detections the network supports. More...
 
uint32_t GetNumClasses () const
 Retrieve the number of object classes supported in the detector. More...
 
const char * GetClassDesc (uint32_t index) const
 Retrieve the description of a particular class. More...
 
const char * GetClassSynset (uint32_t index) const
 Retrieve the class synset category of a particular class. More...
 
const char * GetClassPath () const
 Retrieve the path to the file containing the class descriptions. More...
 
void SetClassColor (uint32_t classIndex, float r, float g, float b, float a=255.0f)
 Set the visualization color of a particular class of object. 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 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...
 
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 path to the network model file. 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...
 
float GetNetworkTime ()
 Retrieve the network runtime (in milliseconds). 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 NetworkType NetworkTypeFromStr (const char *model_name)
 Parse a string to one of the built-in pretrained models. More...
 
static detectNetCreate (NetworkType networkType=PEDNET_MULTI, float threshold=DETECTNET_DEFAULT_THRESHOLD, 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 detectNetCreate (const char *prototxt_path, const char *model_path, const char *mean_binary, const char *class_labels, float threshold=DETECTNET_DEFAULT_THRESHOLD, const char *input=DETECTNET_DEFAULT_INPUT, const char *coverage=DETECTNET_DEFAULT_COVERAGE, const char *bboxes=DETECTNET_DEFAULT_BBOX, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true)
 Load a custom network instance. More...
 
static detectNetCreate (const char *prototxt_path, const char *model_path, float mean_pixel=0.0f, const char *class_labels=NULL, float threshold=DETECTNET_DEFAULT_THRESHOLD, const char *input=DETECTNET_DEFAULT_INPUT, const char *coverage=DETECTNET_DEFAULT_COVERAGE, const char *bboxes=DETECTNET_DEFAULT_BBOX, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true)
 Load a custom network instance. More...
 
static detectNetCreate (const char *model_path, const char *class_labels, float threshold, const char *input, const Dims3 &inputDims, const char *output, const char *numDetections, uint32_t maxBatchSize=DEFAULT_MAX_BATCH_SIZE, precisionType precision=TYPE_FASTEST, deviceType device=DEVICE_GPU, bool allowGPUFallback=true)
 Load a custom network instance of a UFF model. More...
 
static detectNetCreate (int argc, char **argv)
 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 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

 detectNet (float meanPixel=0.0f)
 
bool allocDetections ()
 
bool defaultColors ()
 
void defaultClassDesc ()
 
bool loadClassDesc (const char *filename)
 
bool init (const char *prototxt_path, const char *model_path, const char *mean_binary, const char *class_labels, float threshold, const char *input, const char *coverage, const char *bboxes, uint32_t maxBatchSize, precisionType precision, deviceType device, bool allowGPUFallback)
 
int clusterDetections (Detection *detections, uint32_t width, uint32_t height)
 
- Protected Member Functions inherited from tensorNet
 tensorNet ()
 Constructor. More...
 
bool ProfileModel (const std::string &deployFile, const std::string &modelFile, const char *input, const Dims3 &inputDims, const std::vector< std::string > &outputs, uint32_t maxBatchSize, precisionType precision, deviceType device, bool allowGPUFallback, nvinfer1::IInt8Calibrator *calibrator, std::ostream &modelStream)
 Create and output an optimized network model. 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 mCoverageThreshold
 
float * mClassColors [2]
 
float mMeanPixel
 
std::vector< std::string > mClassDesc
 
std::vector< std::string > mClassSynset
 
std::string mClassPath
 
uint32_t mCustomClasses
 
uint32_t mNumClasses
 
DetectionmDetectionSets [2]
 
uint32_t mDetectionSet
 
uint32_t mMaxDetections
 
- Protected Attributes inherited from tensorNet
tensorNet::Logger gLogger
 
tensorNet::Profiler gProfiler
 
std::string mPrototxtPath
 
std::string mModelPath
 
std::string mMeanPath
 
std::string mInputBlobName
 
std::string mCacheEnginePath
 
std::string mCacheCalibrationPath
 
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
 
uint32_t mWidth
 
uint32_t mHeight
 
uint32_t mInputSize
 
float * mInputCPU
 
float * mInputCUDA
 
float2 mProfilerTimes [PROFILER_TOTAL+1]
 
uint32_t mProfilerQueriesUsed
 
uint32_t mProfilerQueriesDone
 
uint32_t mMaxBatchSize
 
bool mEnableProfiler
 
bool mEnableDebug
 
bool mAllowGPUFallback
 
Dims3 mInputDims
 
std::vector< outputLayermOutputs
 

Static Protected Attributes

static const uint32_t mNumDetectionSets = 16
 

Detailed Description

Object recognition and localization networks with TensorRT support.

Member Enumeration Documentation

◆ NetworkType

Network choice enumeration.

Enumerator
CUSTOM 

Custom model from user.

COCO_AIRPLANE 

MS-COCO airplane class.

COCO_BOTTLE 

MS-COCO bottle class.

COCO_CHAIR 

MS-COCO chair class.

COCO_DOG 

MS-COCO dog class.

FACENET 

Human facial detector trained on FDDB.

PEDNET 

Pedestrian / person detector.

PEDNET_MULTI 

Multi-class pedestrian + baggage detector.

◆ OverlayFlags

Overlay flags (can be OR'd together).

Enumerator
OVERLAY_NONE 

No overlay.

OVERLAY_BOX 

Overlay the object bounding boxes.

OVERLAY_LABEL 

Overlay the class description labels.

Constructor & Destructor Documentation

◆ ~detectNet()

virtual detectNet::~detectNet ( )
virtual

Destory.

◆ detectNet()

detectNet::detectNet ( float  meanPixel = 0.0f)
protected

Member Function Documentation

◆ allocDetections()

bool detectNet::allocDetections ( )
protected

◆ clusterDetections()

int detectNet::clusterDetections ( Detection detections,
uint32_t  width,
uint32_t  height 
)
protected

◆ Create() [1/5]

static detectNet* detectNet::Create ( NetworkType  networkType = PEDNET_MULTI,
float  threshold = DETECTNET_DEFAULT_THRESHOLD,
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
networkTypetype of pre-supported network to load
thresholddefault minimum threshold for detection
maxBatchSizeThe maximum batch size that the network will support and be optimized for.

◆ Create() [2/5]

static detectNet* detectNet::Create ( const char *  prototxt_path,
const char *  model_path,
const char *  mean_binary,
const char *  class_labels,
float  threshold = DETECTNET_DEFAULT_THRESHOLD,
const char *  input = DETECTNET_DEFAULT_INPUT,
const char *  coverage = DETECTNET_DEFAULT_COVERAGE,
const char *  bboxes = DETECTNET_DEFAULT_BBOX,
uint32_t  maxBatchSize = DEFAULT_MAX_BATCH_SIZE,
precisionType  precision = TYPE_FASTEST,
deviceType  device = DEVICE_GPU,
bool  allowGPUFallback = true 
)
static

Load a custom 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
class_labelsFile path to list of class name labels
thresholddefault minimum threshold for detection
inputName of the input layer blob.
coverageName of the output coverage classifier layer blob, which contains the confidence values for each bbox.
bboxesName of the output bounding box layer blob, which contains a grid of rectangles in the image.
maxBatchSizeThe maximum batch size that the network will support and be optimized for.

◆ Create() [3/5]

static detectNet* detectNet::Create ( const char *  prototxt_path,
const char *  model_path,
float  mean_pixel = 0.0f,
const char *  class_labels = NULL,
float  threshold = DETECTNET_DEFAULT_THRESHOLD,
const char *  input = DETECTNET_DEFAULT_INPUT,
const char *  coverage = DETECTNET_DEFAULT_COVERAGE,
const char *  bboxes = DETECTNET_DEFAULT_BBOX,
uint32_t  maxBatchSize = DEFAULT_MAX_BATCH_SIZE,
precisionType  precision = TYPE_FASTEST,
deviceType  device = DEVICE_GPU,
bool  allowGPUFallback = true 
)
static

Load a custom network instance.

Parameters
prototxt_pathFile path to the deployable network prototxt
model_pathFile path to the caffemodel
mean_pixelInput transform subtraction value (use 0.0 if the network already does this)
class_labelsFile path to list of class name labels
thresholddefault minimum threshold for detection
inputName of the input layer blob.
coverageName of the output coverage classifier layer blob, which contains the confidence values for each bbox.
bboxesName of the output bounding box layer blob, which contains a grid of rectangles in the image.
maxBatchSizeThe maximum batch size that the network will support and be optimized for.

◆ Create() [4/5]

static detectNet* detectNet::Create ( const char *  model_path,
const char *  class_labels,
float  threshold,
const char *  input,
const Dims3 inputDims,
const char *  output,
const char *  numDetections,
uint32_t  maxBatchSize = DEFAULT_MAX_BATCH_SIZE,
precisionType  precision = TYPE_FASTEST,
deviceType  device = DEVICE_GPU,
bool  allowGPUFallback = true 
)
static

Load a custom network instance of a UFF model.

Parameters
model_pathFile path to the UFF model
class_labelsFile path to list of class name labels
thresholddefault minimum threshold for detection
inputName of the input layer blob.
inputDimsDimensions of the input layer blob.
outputName of the output layer blob containing the bounding boxes, ect.
numDetectionsName of the output layer blob containing the detection count.
maxBatchSizeThe maximum batch size that the network will support and be optimized for.

◆ Create() [5/5]

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

Load a new network instance by parsing the command line.

◆ defaultClassDesc()

void detectNet::defaultClassDesc ( )
protected

◆ defaultColors()

bool detectNet::defaultColors ( )
protected

◆ Detect() [1/2]

int detectNet::Detect ( float *  input,
uint32_t  width,
uint32_t  height,
Detection **  detections,
uint32_t  overlay = OVERLAY_BOX 
)

Detect object locations from an RGBA image, returning an array containing the detection results.

Parameters
[in]inputfloat4 RGBA input image in CUDA device memory.
[in]widthwidth of the input image in pixels.
[in]heightheight of the input image in pixels.
[out]detectionspointer that will be set to array of detection results (residing in shared CPU/GPU memory)
[in]overlaybitwise OR combination of overlay flags (
See also
OverlayFlags and
Overlay()), or OVERLAY_NONE.
Returns
The number of detected objects, 0 if there were no detected objects, and -1 if an error was encountered.

◆ Detect() [2/2]

int detectNet::Detect ( float *  input,
uint32_t  width,
uint32_t  height,
Detection detections,
uint32_t  overlay = OVERLAY_BOX 
)

Detect object locations in an RGBA image, into an array of the results allocated by the user.

Parameters
[in]inputfloat4 RGBA input image in CUDA device memory.
[in]widthwidth of the input image in pixels.
[in]heightheight of the input image in pixels.
[out]detectionspointer to user-allocated array that will be filled with the detection results.
See also
GetMaxDetections() for the number of detection results that should be allocated in this buffer.
Parameters
[in]overlaybitwise OR combination of overlay flags (
See also
OverlayFlags and
Overlay()), or OVERLAY_NONE.
Returns
The number of detected objects, 0 if there were no detected objects, and -1 if an error was encountered.

◆ GetClassDesc()

const char* detectNet::GetClassDesc ( uint32_t  index) const
inline

Retrieve the description of a particular class.

◆ GetClassPath()

const char* detectNet::GetClassPath ( ) const
inline

Retrieve the path to the file containing the class descriptions.

◆ GetClassSynset()

const char* detectNet::GetClassSynset ( uint32_t  index) const
inline

Retrieve the class synset category of a particular class.

◆ GetMaxDetections()

uint32_t detectNet::GetMaxDetections ( ) const
inline

Retrieve the maximum number of simultaneous detections the network supports.

Knowing this is useful for allocating the buffers to store the output detection results.

◆ GetNumClasses()

uint32_t detectNet::GetNumClasses ( ) const
inline

Retrieve the number of object classes supported in the detector.

◆ GetThreshold()

float detectNet::GetThreshold ( ) const
inline

Retrieve the minimum threshold for detection.

TODO: change this to per-class in the future

◆ init()

bool detectNet::init ( const char *  prototxt_path,
const char *  model_path,
const char *  mean_binary,
const char *  class_labels,
float  threshold,
const char *  input,
const char *  coverage,
const char *  bboxes,
uint32_t  maxBatchSize,
precisionType  precision,
deviceType  device,
bool  allowGPUFallback 
)
protected

◆ loadClassDesc()

bool detectNet::loadClassDesc ( const char *  filename)
protected

◆ NetworkTypeFromStr()

static NetworkType detectNet::NetworkTypeFromStr ( const char *  model_name)
static

Parse a string to one of the built-in pretrained models.

Valid names are "pednet", "multiped", "facenet", "face", "coco-airplane", "airplane", "coco-bottle", "bottle", "coco-chair", "chair", "coco-dog", or "dog".

Returns
one of the detectNet::NetworkType enums, or detectNet::CUSTOM on invalid string.

◆ Overlay()

bool detectNet::Overlay ( float *  input,
float *  output,
uint32_t  width,
uint32_t  height,
Detection detections,
uint32_t  numDetections,
uint32_t  flags = OVERLAY_BOX 
)

Draw the detected bounding boxes overlayed on an RGBA image.

Note
Overlay() will automatically be called by default by Detect(), if the overlay parameter is true
Parameters
inputfloat4 RGBA input image in CUDA device memory.
outputfloat4 RGBA output image in CUDA device memory.
detectionsArray of detections allocated in CUDA device memory.

◆ SetClassColor()

void detectNet::SetClassColor ( uint32_t  classIndex,
float  r,
float  g,
float  b,
float  a = 255.0f 
)

Set the visualization color of a particular class of object.

◆ SetThreshold()

void detectNet::SetThreshold ( float  threshold)
inline

Set the minimum threshold for detection.

◆ Usage()

static const char* detectNet::Usage ( )
inlinestatic

Usage string for command line arguments to Create()

Member Data Documentation

◆ mClassColors

float* detectNet::mClassColors[2]
protected

◆ mClassDesc

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

◆ mClassPath

std::string detectNet::mClassPath
protected

◆ mClassSynset

std::vector<std::string> detectNet::mClassSynset
protected

◆ mCoverageThreshold

float detectNet::mCoverageThreshold
protected

◆ mCustomClasses

uint32_t detectNet::mCustomClasses
protected

◆ mDetectionSet

uint32_t detectNet::mDetectionSet
protected

◆ mDetectionSets

Detection* detectNet::mDetectionSets[2]
protected

◆ mMaxDetections

uint32_t detectNet::mMaxDetections
protected

◆ mMeanPixel

float detectNet::mMeanPixel
protected

◆ mNumClasses

uint32_t detectNet::mNumClasses
protected

◆ mNumDetectionSets

const uint32_t detectNet::mNumDetectionSets = 16
staticprotected

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