Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions botsort/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ endif()
file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")

# Create library
add_library(${PROJECT_NAME} SHARED ${SOURCES})
if(MSVC)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
else()
add_library(${PROJECT_NAME} SHARED ${SOURCES})
endif()

if(MSVC)
target_link_options(${PROJECT_NAME} PRIVATE "/NODEFAULTLIB:LIBCMT")
#target_link_options(${PROJECT_NAME} PRIVATE "/NODEFAULTLIB:LIBCMTD")
#target_link_options(${PROJECT_NAME} PRIVATE "/NODEFAULTLIB:MSVCRTD")
target_link_libraries(${PROJECT_NAME} ws2_32)
endif()


# Set include directories
target_include_directories(${PROJECT_NAME} PUBLIC
Expand All @@ -35,24 +47,39 @@ find_package(Eigen3 REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${EIGEN3_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} Eigen3::Eigen)

# Find and link Boost
find_package(Boost REQUIRED COMPONENTS filesystem)
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

# Find and link CUDA
find_package(CUDA QUIET)

if(NOT ${CUDA_FOUND})
message(WARNING "CUDA not found, ReID won't be built")
message(WARNING "CUDA not found, ReID will be built with opencv_dnn")
target_sources(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src/ReID.cpp)

remove_definitions(-DUSE_TRT_REID)
else()
message(STATUS "CUDA version ${CUDA_VERSION_STRING} found")
target_include_directories(${PROJECT_NAME} PUBLIC ${CUDA_INCLUDE_DIRS})

find_library(TRT_NVINFER NAMES nvinfer PATHS ${TENSORRT_DIR} PATH_SUFFIXES lib lib64)
find_library(TRT_NVONNXPARSER NAMES nvonnxparser PATHS ${TENSORRT_DIR} PATH_SUFFIXES lib lib64)
find_path(TRT_INCLUDE_DIR NAMES NvInfer.h PATHS ${TENSORRT_DIR} PATH_SUFFIXES include)

if (NOT TRT_NVINFER OR NOT TRT_NVONNXPARSER OR NOT TRT_INCLUDE_DIR)
message(FATAL_ERROR "Not all TensorRT was found. Check TENSORRT_DIR.")
else()
message("TRT_INCLUDE_DIR: ${TRT_INCLUDE_DIR}, TRT_NVINFER: ${TRT_NVINFER}, TRT_NVONNXPARSER: ${TRT_NVONNXPARSER}")
endif()

target_include_directories(${PROJECT_NAME} PRIVATE ${TRT_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${TRT_NVINFER})
target_link_libraries(${PROJECT_NAME} ${TRT_NVONNXPARSER})

target_sources(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/src/TRT_InferenceEngine/TensorRT_InferenceEngine.cpp
${PROJECT_SOURCE_DIR}/src/ReID.cpp)
target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES} nvonnxparser nvinfer)
target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES})

add_definitions(-DUSE_TRT_REID)
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
Expand All @@ -64,4 +91,4 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
else()
add_definitions(-DPROFILE=1)
add_compile_options(-O3)
endif()
endif()
4 changes: 2 additions & 2 deletions botsort/include/DataType.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <cstdint>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <optional>
#include <utility>
#include <vector>
Expand Down
24 changes: 6 additions & 18 deletions botsort/include/ReID.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,20 @@

#include "DataType.h"
#include "ReIDParams.h"
#include "TRT_InferenceEngine/TensorRT_InferenceEngine.h"

class ReIDModel
{
public:
ReIDModel(const ReIDParams &params, const std::string &onnx_model_path);
~ReIDModel() = default;
~ReIDModel();

void pre_process(cv::Mat &image);
FeatureVector extract_features(cv::Mat &image);

const std::string &get_distance_metric() const
{
return _distance_metric;
}
const std::string &get_distance_metric() const noexcept;

private:
void _load_params_from_config(const ReIDParams &params);
class InferenceImpl;


private:
inference_backend::TRTOptimizerParams _model_optimization_params;
std::unique_ptr<inference_backend::TensorRTInferenceEngine>
_trt_inference_engine;
u_int8_t _trt_logging_level;
cv::Size _input_size;

std::string _onnx_model_path, _distance_metric;
private:

InferenceImpl *_inference_impl = nullptr;
};
18 changes: 5 additions & 13 deletions botsort/include/TRT_InferenceEngine/TensorRT_InferenceEngine.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#pragma once

#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>
#include <fstream>
#include <memory>
#include <numeric>
#include <string>
#include <vector>

#include <NvInfer.h>
#include <NvOnnxParser.h>

#ifndef _MSC_VER
#include <unistd.h>
#endif

#include <boost/filesystem.hpp>
#include <opencv2/opencv.hpp>

#include "TRT_Logger.h"
Expand Down Expand Up @@ -116,7 +110,7 @@ class TensorRTInferenceEngine

public:
TensorRTInferenceEngine(TRTOptimizerParams &optimization_params,
u_int8_t logging_level);
int8_t logging_level);
~TensorRTInferenceEngine();

bool load_model(const std::string &onnx_model_path);
Expand All @@ -126,14 +120,12 @@ class TensorRTInferenceEngine
private:
// Const methods
std::string get_engine_path(const std::string &onnx_model_path) const;
bool file_exists(const std::string &name) const;
size_t get_size_by_dims(const nvinfer1::Dims &dims,
int element_size = 1) const;


// Non-const methods
void _set_optimization_params(const TRTOptimizerParams &params);
void _init_TRT_logger(u_int8_t logging_level);
void _init_TRT_logger(int8_t logging_level);

void _build_engine(const std::string &onnx_model_path);
bool _deserialize_engine(const std::string &engine_path);
Expand Down
81 changes: 5 additions & 76 deletions botsort/include/lapjv.h
Original file line number Diff line number Diff line change
@@ -1,79 +1,8 @@
// Directly taken from: https://github.com/ifzhang/ByteTrack/blob/main/deploy/ncnn/cpp/include/lapjv.h
#pragma once

#ifndef LAPJV_H
#define LAPJV_H
#include <cstddef>
#include <vector>

#define LARGE 1000000
typedef float lapjv_t;

#if !defined TRUE
#define TRUE 1
#endif
#if !defined FALSE
#define FALSE 0
#endif

#define NEW(x, t, n) \
if ((x = (t *) malloc(sizeof(t) * (n))) == 0) { return -1; }
#define FREE(x) \
if (x != 0) \
{ \
free(x); \
x = 0; \
}
#define SWAP_INDICES(a, b) \
{ \
int_t _temp_index = a; \
a = b; \
b = _temp_index; \
}

#if 0
#include <assert.h>
#define ASSERT(cond) assert(cond)
#define PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define PRINT_COST_ARRAY(a, n) \
while (1) \
{ \
printf(#a " = ["); \
if ((n) > 0) \
{ \
printf("%f", (a)[0]); \
for (uint_t j = 1; j < n; j++) { printf(", %f", (a)[j]); } \
} \
printf("]\n"); \
break; \
}
#define PRINT_INDEX_ARRAY(a, n) \
while (1) \
{ \
printf(#a " = ["); \
if ((n) > 0) \
{ \
printf("%d", (a)[0]); \
for (uint_t j = 1; j < n; j++) { printf(", %d", (a)[j]); } \
} \
printf("]\n"); \
break; \
}
#else
#define ASSERT(cond)
#define PRINTF(fmt, ...)
#define PRINT_COST_ARRAY(a, n)
#define PRINT_INDEX_ARRAY(a, n)
#endif


typedef signed int int_t;
typedef unsigned int uint_t;
typedef double cost_t;
typedef char boolean;
typedef enum fp_t
{
FP_1 = 1,
FP_2 = 2,
FP_DYNAMIC = 3
} fp_t;

extern int_t lapjv_internal(const uint_t n, cost_t *cost[], int_t *x, int_t *y);

#endif// LAPJV_H
int lapjv_internal(const size_t n, const std::vector<std::vector<lapjv_t>>& cost, std::vector<int>& x, std::vector<int>& y);
6 changes: 6 additions & 0 deletions botsort/include/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@

#if PROFILE
#define PROFILE_SCOPE(name) Profiler timer##__LINE__(name)

#ifdef _MSC_VER
#define PROFILE_FUNCTION() PROFILE_SCOPE(__FUNCSIG__)
#else
#define PROFILE_FUNCTION() PROFILE_SCOPE(__PRETTY_FUNCTION__)
#endif

#else
#define PROFILE_SCOPE(name)
#define PROFILE_FUNCTION()
Expand Down
2 changes: 1 addition & 1 deletion botsort/src/KalmanFilter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "KalmanFilter.h"

#include <eigen3/Eigen/Cholesky>
#include <Eigen/Cholesky>

namespace bot_kalman
{
Expand Down
2 changes: 1 addition & 1 deletion botsort/src/KalmanFilterAccBased.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "KalmanFilterAccBased.h"

#include <eigen3/Eigen/Cholesky>
#include <Eigen/Cholesky>

namespace acc_kalman
{
Expand Down
Loading