Hi @fanzh and @gff1038m Can you please help me in solving the issue,
I am developing a face Recognition with the Deep Stream.
My system configuration :
- GPU: NVIDIA A6000
- TensorRT Version: 8.6.1
- CUDA Version: 12.2
DeepStream Version: 7.0
I use Facedetectir model from the NGC catalog to detect the faces, when I use that model I got the performance issue while the model is detecting at some frames while in other frames no faces are detecting , so I changed to the yolov8n face detection model and convert that into .engine model using code :
from ultralytics import YOLO
model = YOLO(‘yolov8n-face.pt’) model.export(format=‘engine’,device=0, half=False) # Full precision
When I use this converted engine with the Deep Stream I am getting issue “failed to build the engine”
So I tried to load the engine with the trtexec command then I got issue in dserialization
So, to resolve this issue I converted the model into .onnx and then .engine, dserialization issue is solved, but no faces are detecting from the frames
my yolo model config file is
yolov8_infer_config.txt (835 Bytes)
I also tried by keep the network mode as 100 for yolo models.
my custom parser code used for parsing the yolov8n face detection model output is :
include
include
include
include
include
include “nvdsinfer_custom_impl.h”
static const int NUM_CLASSES_YOLO = 1; // Face detection
static const float CONFIDENCE_THRESHOLD = 0.5;
extern “C” bool NvDsInferParseCustomYoloV8(
std::vector const& outputLayersInfo,
NvDsInferNetworkInfo const& networkInfo,
NvDsInferParseDetectionParams const& detectionParams,
std::vector& objectList)
{
if (outputLayersInfo.empty()) {
std::cerr << “ERROR: Could not find output layer in bbox parsing” << std::endl;
return false;
}
const NvDsInferLayerInfo& layer = outputLayersInfo[0];
// Validate output dimensions
if (layer.inferDims.numDims != 2) {
std::cerr << "ERROR: Expected 2 dimensions in output tensor, but got "
<< layer.inferDims.numDims << " (Shape: ";
for (int i = 0; i < layer.inferDims.numDims; i++) {
std::cerr << layer.inferDims.d[i] << " ";
}
std::cerr << ")" << std::endl;
return false;
}
if (!layer.buffer) {
std::cerr << "ERROR: Layer buffer is null!" << std::endl;
return false;
}
//int batch_size = layer.inferDims.d[0]; // Number of batches
int num_boxes = layer.inferDims.d[0]; // 20 (anchors per feature map point)
int num_features = layer.inferDims.d[1]; // 8400 (grid points)
std::cout << "Processing output with dimensions: "
<< num_boxes << "x" << num_features << std::endl;
if (num_features < 6) { // Must have at least x, y, w, h, and confidence
std::cerr << "ERROR: Feature vector too small " << std::endl;
return false;
}
const float* output = (const float*)layer.buffer;
for (int i = 0; i < num_boxes; i++) {
float x = output[i * num_features];
float y = output[i * num_features + 1];
float w = output[i * num_features + 2];
float h = output[i * num_features + 3];
float confidence = output[i * num_features + 4];
if (confidence < CONFIDENCE_THRESHOLD) continue; // Ignore low-confidence detections
NvDsInferParseObjectInfo obj{0};
// Normalize the bbox coordinates if necessary
float scale_x = networkInfo.width / 1.0f;
float scale_y = networkInfo.height / 1.0f;
if (x <= 1.0 && y <= 1.0 && w <= 1.0 && h <= 1.0) {
x *= scale_x;
y *= scale_y;
w *= scale_x;
h *= scale_y;
}
obj.left = x - w / 2;
obj.top = y - h / 2;
obj.width = w;
obj.height = h;
// Ensure bbox stays inside image bounds
obj.left = std::max(0.0f, std::min(obj.left, (float)networkInfo.width - 1));
obj.top = std::max(0.0f, std::min(obj.top, (float)networkInfo.height - 1));
obj.width = std::min(obj.width, (float)networkInfo.width - obj.left);
obj.height = std::min(obj.height, (float)networkInfo.height - obj.top);
obj.detectionConfidence = confidence;
obj.classId = (num_features > 5) ? (int)output[i * num_features + 5] : 0; // Class ID
if (obj.width > 0 && obj.height > 0) {
objectList.push_back(obj);
}
}
return true;
}
CHECK_CUSTOM_PARSE_FUNC_PROTOTYPE(NvDsInferParseCustomYoloV8);
Note: My yolov8n face detection model is a dynamic model while converting into deepstream we need set the shapes,I set the shapes as 3,640,640 for the model I am using . Help me in cracking this.