Yolov8 Model Crashing TensorRT

Description

I am training a yolov8s model for TensorRT inference in C++. Calling any function member of my constructed Cuda Engine results in a segmentation fault.

I used yolov8 to convert my model to an onnx and tensorrt “.engine” file. It’s important to note, that I have no issue converting or inferring using tensorrt using the yolov8 library, I can only not get it working for my code.

I can load my models using “deserializeCudaEngine” with no issue, but if I use any function on my engine object, it causes a segmentation fault.

I also tried loading my model for conversion from onnx using a builder, outlined by the tensorrt tutorials. This had a segmentation fault on createParser.

I have both followed the nvidia tutorial and found online examples, but have not been able to get anything working. This is just a prototype application running on Windows 10, eventually it will be running on a Jetson Nano, but I’d like to get something displayable on windows too.

My best guess is that this is either some kind of de-serialization issue, or a GPU issue. Is there any way to troubleshoot and discover which? How would I debug an issue like this myself?

Environment

TensorRT Version: 8.6.1.6
GPU Type: Quadro T1000
Nvidia Driver Version: 522.06
CUDA Version: 11.8.0
CUDNN Version: 8.9.7.29
Operating System + Version: Windows 10 19045.3930
Python Version (if applicable): 3.9.9 (only used by yolov8)
TensorFlow Version (if applicable): N/A
PyTorch Version (if applicable): N/A
Baremetal or Container (if container which image + tag): N/A

Relevant Files

Simple Logger

class Logger : public nvinfer1::ILogger {
    void log(Severity severity, const char *msg) noexcept override {
        // Suppress info messages
        if (severity <= Severity::kWARNING) {
            std::cout << msg << std::endl;
        }
    }
};

Deserialize Model (in main loop)

    Logger logger;
    auto runtime = nvinfer1::createInferRuntime(logger);
    std::string path = "../res/models/yolov8s.engine";
    if(!std::filesystem::exists(path)) {
        std::cout << "Path '" << path << "' does not exist!" << std::endl;
    }

    // Load file as binary
    std::ifstream file(path, std::ios::in | std::ios::binary);
    if(!file.good()) {
        std::cout << "Error loading file" << std::endl;
    }

    // Find file length
    file.seekg(0, file.end);
    size_t size = file.tellg();
    file.seekg(0, file.beg);

    // Load file data
    auto buffer = std::unique_ptr<char[]>(new char[size]);
    file.read(buffer.get(), size);

    // Close file
    file.close();

    // Deserialize inferrence engine
    nvinfer1::ICudaEngine *engine = runtime->deserializeCudaEngine(buffer.get(), size);
    engine->getNbBindings(); // Seg fault here

CMake File

cmake_minimum_required(VERSION 3.5)
project(det-cpp)


set(SRC_DIR
    ${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp
)

set(OpenCV_DIR C:/Users/hyvikozy/Documents/libs/opencv/build)

# TensorRT
# TODO: These are windows directories, need to be platform agnostic
set(TENSORRT_ROOT "C:/Program Files/TensorRT-8.6.1.6")
set(LIBCUDNN_ROOT "C:/Program Files/NVIDIA/CUDNN/v8.9")

find_package(CUDA REQUIRED)

include_directories(
    ${CMAKE_SOURCE_DIR}/include 
    ${OpenCV_INCLUDE_DIRS} 
    ${CUDA_INCLUDE_DIRS}
    ${TENSORRT_ROOT}/include
)

add_executable(det-cpp ${OpenCV_LIBS} ${SRC_DIR})
find_package(OpenCV REQUIRED)

#TODO: lib files dont look like this on linux
target_link_libraries(det-cpp 
    ${OpenCV_LIBS}
    ${CUDA_LIBRARIES}
    ${TENSORRT_ROOT}/lib/nvinfer.lib
    ${TENSORRT_ROOT}/lib/nvinfer_plugin.lib
    ${TENSORRT_ROOT}/lib/nvonnxparser.lib
    ${TENSORRT_ROOT}/lib/nvparsers.lib
    ${LIBCUDNN_ROOT}/lib/cudnn.lib
    ${LIBCUDNN_ROOT}/lib/cudnn_ops_infer.lib
)

Steps To Reproduce

  1. Setup Yolov8 using guide. Download Yolov8 model.
  2. Convert to TensorRT
  3. Setup A CMake C++ project using TensorRT, Cudnn and CUDA support (Also OpenCV).
  4. Use included code.
  5. Crashes.

Hi @hyvikozy ,
Can you please help us with the logs as well.
Thanks