23 #ifndef __DETECT_NET_H__ 24 #define __DETECT_NET_H__ 34 #define DETECTNET_DEFAULT_INPUT "data" 40 #define DETECTNET_DEFAULT_COVERAGE "coverage" 46 #define DETECTNET_DEFAULT_BBOX "bboxes" 52 #define DETECTNET_DEFAULT_THRESHOLD 0.5f 58 #define DETECTNET_USAGE_STRING "detectNet arguments: \n" \ 59 " --network NETWORK pre-trained model to load, one of the following:\n" \ 60 " * pednet (default)\n" \ 63 " * ssd-mobilenet-v1\n" \ 64 " * ssd-mobilenet-v2\n" \ 65 " * ssd-inception-v2\n" \ 66 " * coco-airplane\n" \ 70 " --model MODEL path to custom model to load (.caffemodel, .uff, or .onnx)\n" \ 71 " --prototxt PROTOTXT path to custom prototxt to load (for .caffemodel only)\n" \ 72 " --class_labels LABELS path to text file containing the labels for each class\n" \ 73 " --threshold THRESHOLD minimum threshold for detection (default is 0.5)\n" \ 74 " --input_blob INPUT name of the input layer (default is '" DETECTNET_DEFAULT_INPUT "')\n" \ 75 " --output_cvg COVERAGE name of the coverge output layer (default is '" DETECTNET_DEFAULT_COVERAGE "')\n" \ 76 " --output_bbox BOXES name of the bounding output layer (default is '" DETECTNET_DEFAULT_BBOX "')\n" \ 77 " --mean_pixel PIXEL mean pixel value to subtract from input (default is 0.0)\n" \ 78 " --batch_size BATCH maximum batch size (default is 1)\n" 114 inline void Center(
float* x,
float* y )
const {
if(x) *x = Left +
Width() * 0.5f;
if(y) *y = Top +
Height() * 0.5f; }
117 inline bool Contains(
float x,
float y )
const {
return x >= Left && x <= Right && y >= Top && y <=
Bottom; }
123 inline bool Overlaps(
float x1,
float y1,
float x2,
float y2 )
const {
return !(x1 > Right || x2 < Left || y1 > Bottom || y2 <
Top); }
126 inline bool Expand(
float x1,
float y1,
float x2,
float y2 ) {
if(!
Overlaps(x1, y1, x2, y2))
return false; Left = fminf(x1, Left); Top = fminf(y1, Top); Right = fmaxf(x2, Right); Bottom = fmaxf(y2, Bottom);
return true; }
129 inline bool Expand(
const Detection& det ) {
if(!
Overlaps(det))
return false; Left = fminf(det.
Left, Left); Top = fminf(det.
Top, Top); Right = fmaxf(det.
Right, Right); Bottom = fmaxf(det.
Bottom, Bottom);
return true; }
132 inline void Reset() { Instance = 0; ClassID = 0; Confidence = 0; Left = 0; Right = 0; Top = 0; Bottom = 0; }
162 #if NV_TENSORRT_MAJOR > 4 199 static detectNet*
Create(
const char* prototxt_path,
const char* model_path,
const char* mean_binary,
220 static detectNet*
Create(
const char* prototxt_path,
const char* model_path,
float mean_pixel=0.0f,
240 static detectNet*
Create(
const char* model_path,
const char* class_labels,
float threshold,
241 const char* input,
const Dims3& inputDims,
242 const char* output,
const char* numDetections,
292 bool Overlay(
float* input,
float* output, uint32_t width, uint32_t height,
Detection* detections, uint32_t numDetections, uint32_t flags=
OVERLAY_BOX );
334 void SetClassColor( uint32_t classIndex,
float r,
float g,
float b,
float a=255.0f );
347 bool init(
const char* prototxt_path,
const char* model_path,
const char* mean_binary,
const char* class_labels,
348 float threshold,
const char* input,
const char* coverage,
const char* bboxes, uint32_t maxBatchSize,
Detection * mDetectionSets[2]
Definition: detectNet.h:364
Pedestrian / person detector.
Definition: detectNet.h:159
MS-COCO chair class.
Definition: detectNet.h:156
bool Contains(float x, float y) const
Return true if the bounding boxes overlap.
Definition: detectNet.h:117
void SetThreshold(float threshold)
Set the minimum threshold for detection.
Definition: detectNet.h:303
float Top
Top bounding box cooridnate (in pixels)
Definition: detectNet.h:101
precisionType
Enumeration for indicating the desired precision that the network should run in, if available in hard...
Definition: tensorNet.h:79
GPU (if multiple GPUs are present, a specific GPU can be selected with cudaSetDevice() ...
Definition: tensorNet.h:108
std::vector< std::string > mClassSynset
Definition: detectNet.h:358
bool Expand(const Detection &det)
Reset all member variables to zero.
Definition: detectNet.h:129
float Left
Left bounding box coordinate (in pixels)
Definition: detectNet.h:99
MS-COCO bottle class.
Definition: detectNet.h:155
Overlay the object bounding boxes.
Definition: detectNet.h:144
#define DETECTNET_DEFAULT_BBOX
Name of default output blob of the grid of bounding boxes for DetectNet caffe model.
Definition: detectNet.h:46
std::string mClassPath
Definition: detectNet.h:360
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...
Detection()
Definition: detectNet.h:135
#define DETECTNET_DEFAULT_COVERAGE
Name of default output blob of the coverage map for DetectNet caffe model.
Definition: detectNet.h:40
const char * GetClassSynset(uint32_t index) const
Retrieve the class synset category of a particular class.
Definition: detectNet.h:324
#define DETECTNET_USAGE_STRING
Command-line options able to be passed to imageNet::Create()
Definition: detectNet.h:58
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.
float GetThreshold() const
Retrieve the minimum threshold for detection.
Definition: detectNet.h:298
deviceType
Enumeration for indicating the desired device that the network should run on, if available in hardwar...
Definition: tensorNet.h:106
The fastest detected precision should be use (i.e.
Definition: tensorNet.h:82
Overlay the class description labels.
Definition: detectNet.h:145
float * mClassColors[2]
Definition: detectNet.h:354
std::vector< std::string > mClassDesc
Definition: detectNet.h:357
static 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)
Load a new network instance.
static NetworkType NetworkTypeFromStr(const char *model_name)
Parse a string to one of the built-in pretrained models.
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)
uint32_t mDetectionSet
Definition: detectNet.h:365
MS-COCO dog class.
Definition: detectNet.h:157
uint32_t ClassID
Class index of the detected object.
Definition: detectNet.h:95
#define DETECTNET_DEFAULT_INPUT
Name of default input blob for DetectNet caffe model.
Definition: detectNet.h:34
Multi-class pedestrian + baggage detector.
Definition: detectNet.h:160
uint32_t GetNumClasses() const
Retrieve the number of object classes supported in the detector.
Definition: detectNet.h:314
bool Expand(float x1, float y1, float x2, float y2)
Expand the bounding box if they overlap (return true if so)
Definition: detectNet.h:126
MS-COCO airplane class.
Definition: detectNet.h:154
Object Detection result.
Definition: detectNet.h:91
float mMeanPixel
Definition: detectNet.h:355
const char * GetClassDesc(uint32_t index) const
Retrieve the description of a particular class.
Definition: detectNet.h:319
uint32_t Instance
Index of this unique object instance.
Definition: detectNet.h:94
static const uint32_t mNumDetectionSets
Definition: detectNet.h:368
No overlay.
Definition: detectNet.h:143
void Center(float *x, float *y) const
Return true if the coordinate is inside the bounding box.
Definition: detectNet.h:114
Human facial detector trained on FDDB.
Definition: detectNet.h:158
bool loadClassDesc(const char *filename)
float Height() const
Calculate the area of the object.
Definition: detectNet.h:108
float Right
Right bounding box coordinate (in pixels)
Definition: detectNet.h:100
uint32_t mCustomClasses
Definition: detectNet.h:361
float Area() const
Return the center of the object.
Definition: detectNet.h:111
#define DEFAULT_MAX_BATCH_SIZE
Default maximum batch size.
Definition: tensorNet.h:65
uint32_t GetMaxDetections() const
Retrieve the maximum number of simultaneous detections the network supports.
Definition: detectNet.h:309
Abstract class for loading a tensor network with TensorRT.
Definition: tensorNet.h:188
Object recognition and localization networks with TensorRT support.
Definition: detectNet.h:85
uint32_t mMaxDetections
Definition: detectNet.h:366
static const char * Usage()
Usage string for command line arguments to Create()
Definition: detectNet.h:255
bool Overlaps(float x1, float y1, float x2, float y2) const
Expand the bounding box if they overlap (return true if so)
Definition: detectNet.h:123
float mCoverageThreshold
Definition: detectNet.h:353
const char * GetClassPath() const
Retrieve the path to the file containing the class descriptions.
Definition: detectNet.h:329
float Bottom
Bottom bounding box coordinate (in pixels)
Definition: detectNet.h:102
NetworkType
Network choice enumeration.
Definition: detectNet.h:151
float Confidence
Confidence value of the detected object.
Definition: detectNet.h:96
detectNet(float meanPixel=0.0f)
#define DETECTNET_DEFAULT_THRESHOLD
Default value of the minimum detection threshold.
Definition: detectNet.h:52
uint32_t mNumClasses
Definition: detectNet.h:362
bool Overlaps(const Detection &det) const
Return true if the bounding boxes overlap.
Definition: detectNet.h:120
virtual ~detectNet()
Destory.
OverlayFlags
Overlay flags (can be OR'd together).
Definition: detectNet.h:141
void Reset()
Default constructor.
Definition: detectNet.h:132
int clusterDetections(Detection *detections, uint32_t width, uint32_t height)
float Width() const
Calculate the height of the object.
Definition: detectNet.h:105
Custom model from user.
Definition: detectNet.h:153
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.
nvinfer1::Dims3 Dims3
Definition: tensorNet.h:48