Skip to content

Commit

Permalink
MAINT: reorganize DL inference code.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddkiva committed Dec 11, 2023
1 parent 92bbde1 commit 6ce3fe4
Show file tree
Hide file tree
Showing 44 changed files with 203 additions and 143 deletions.
1 change: 0 additions & 1 deletion cpp/drafts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ add_subdirectory(ChessboardDetection)
add_subdirectory(Calibration)
add_subdirectory(Compute)
add_subdirectory(MatchPropagation)
add_subdirectory(NeuralNetworks)
add_subdirectory(NuScenes)
add_subdirectory(Taskflow)

Expand Down
2 changes: 0 additions & 2 deletions cpp/drafts/NeuralNetworks/CMakeLists.txt

This file was deleted.

12 changes: 0 additions & 12 deletions cpp/drafts/NeuralNetworks/Darknet/CMakeLists.txt

This file was deleted.

37 changes: 0 additions & 37 deletions cpp/drafts/NeuralNetworks/TensorRT/CMakeLists.txt

This file was deleted.

2 changes: 2 additions & 0 deletions cpp/examples/Sara/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ add_subdirectory(MultiViewGeometry)
if (SARA_BUILD_VIDEOIO)
add_subdirectory(VideoIO)
endif ()

add_subdirectory(NeuralNetworks)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ foreach (file ${neuralnetworks_SOURCE_FILES})
DO::Sara::ImageIO
DO::Sara::VideoIO
DO::Sara::Darknet
Boost::filesystem
$<$<BOOL:${OpenMP_CXX_FOUND}>:OpenMP::OpenMP_CXX>)
set_target_properties(${filename}
PROPERTIES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/Darknet/Network.hpp>
#include <drafts/NeuralNetworks/Darknet/Parser.hpp>
#include <drafts/NeuralNetworks/Darknet/YoloUtilities.hpp>

#include <DO/Sara/Core.hpp>
#include <DO/Sara/Core/TicToc.hpp>

#include <DO/Sara/ImageProcessing.hpp>

#include <DO/Sara/Graphics.hpp>
#include <DO/Sara/ImageIO.hpp>
#include <DO/Sara/ImageProcessing.hpp>
#include <DO/Sara/VideoIO.hpp>

#include <boost/filesystem.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Network.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Parser.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/YoloUtilities.hpp>


#include <filesystem>
#include <iomanip>

#ifdef _OPENMP
#include <omp.h>
# include <omp.h>
#endif


namespace sara = DO::Sara;
namespace d = DO::Sara::Darknet;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;


// The API.
Expand Down
2 changes: 2 additions & 0 deletions cpp/examples/Shakti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ endif()

add_subdirectory(OpenCL)
add_subdirectory(Vulkan)

add_subdirectory(TensorRT)
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ foreach(file ${TRT_SOURCE_FILES})
DO::Sara::VideoIO
DO::Sara::ImageProcessing
DO::Sara::Darknet
DO::Sara::TensorRT
DO::Shakti::Cuda::MultiArray
DO::Shakti::Cuda::Utilities)
DO::Shakti::Cuda::Utilities
DO::Shakti::Cuda::TensorRT)

set_target_properties(
${filename} PROPERTIES COMPILE_FLAGS ${SARA_DEFINITIONS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/Darknet/YoloUtilities.hpp>
#include <drafts/NeuralNetworks/TensorRT/DarknetParser.hpp>
#include <drafts/NeuralNetworks/TensorRT/InferenceExecutor.hpp>
#include <DO/Shakti/Cuda/TensorRT/DarknetParser.hpp>
#include <DO/Shakti/Cuda/TensorRT/InferenceExecutor.hpp>

#include <DO/Sara/Graphics.hpp>
#include <DO/Sara/ImageProcessing/FastColorConversion.hpp>
#include <DO/Sara/ImageProcessing/Resize.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/YoloUtilities.hpp>
#include <DO/Sara/VideoIO.hpp>

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


namespace sara = DO::Sara;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
namespace trt = sara::TensorRT;
namespace d = sara::Darknet;

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/DO/Sara/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ include(UseDOSaraMultiViewGeometry)
include(UseDOSaraRANSAC)

include(UseDOSaraVisualization)

add_subdirectory(NeuralNetworks)
1 change: 1 addition & 0 deletions cpp/src/DO/Sara/NeuralNetworks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Darknet)
10 changes: 10 additions & 0 deletions cpp/src/DO/Sara/NeuralNetworks/Darknet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
file(GLOB DO_Sara_Darknet_SOURCE_FILES FILES *.hpp *.cpp)

add_library(DO_Sara_Darknet ${DO_Sara_Darknet_SOURCE_FILES})
add_library(DO::Sara::Darknet ALIAS DO_Sara_Darknet)

target_link_libraries(
DO_Sara_Darknet
PUBLIC DO::Sara::Core DO::Sara::ImageProcessing
PRIVATE Boost::filesystem)
set_property(TARGET DO_Sara_Darknet PROPERTY FOLDER "Libraries/Sara")
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

#pragma once

#include <drafts/NeuralNetworks/Darknet/Network.hpp>

#include <DO/Sara/Graphics.hpp>
#include <DO/Sara/ImageProcessing.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Network.hpp>

#include <boost/filesystem.hpp>

#include <filesystem>
#include <string>


Expand Down Expand Up @@ -45,7 +43,7 @@ namespace DO::Sara::Darknet {
// CAVEAT: this is sensitive to the CPU architecture endianness.
inline auto read_all_intermediate_outputs(const std::string& dir_path)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;

auto stringify = [](int n) {
std::ostringstream ss;
Expand Down Expand Up @@ -169,7 +167,7 @@ namespace DO::Sara::Darknet {
inline auto check_yolov4_tiny_implementation(Network& model,
const std::string& output_dir)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;

if (!fs::exists(output_dir))
throw std::runtime_error{"Ouput directory " + output_dir +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/Darknet/Layer.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Layer.hpp>

#include <boost/algorithm/string.hpp>


using namespace DO::Sara::Darknet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <DO/Sara/Core/Tensor.hpp>
#include <DO/Sara/ImageProcessing/GemmBasedConvolution.hpp>

#include <boost/algorithm/string.hpp>
#include <memory>


namespace DO::Sara::Darknet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

#include <DO/Sara/Core/MultiArray/Slice.hpp>
#include <DO/Sara/Core/TicToc.hpp>

#include <DO/Sara/ImageProcessing/GemmBasedConvolution.hpp>

#include <drafts/NeuralNetworks/Darknet/Layer.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Layer.hpp>

#include <iomanip>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/Darknet/Parser.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Parser.hpp>

#include <boost/algorithm/string.hpp>

#include <fstream>

Expand Down Expand Up @@ -206,7 +208,7 @@ namespace DO::Sara::Darknet {
}


auto load_yolov4_tiny_model(const boost::filesystem::path& model_dir_path)
auto load_yolov4_tiny_model(const std::filesystem::path& model_dir_path)
-> Network
{
const auto cfg_filepath = model_dir_path / "yolov4-tiny.cfg";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

#pragma once

#include <drafts/NeuralNetworks/Darknet/Layer.hpp>
#include <drafts/NeuralNetworks/Darknet/Network.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Layer.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Network.hpp>

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


namespace DO::Sara::Darknet {
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace DO::Sara::Darknet {
};


auto load_yolov4_tiny_model(const boost::filesystem::path& model_dir_path)
auto load_yolov4_tiny_model(const std::filesystem::path& model_dir_path)
-> Network;

} // namespace DO::Sara::Darknet
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/Darknet/YoloUtilities.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/YoloUtilities.hpp>


namespace DO::Sara::Darknet {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/DO/Shakti/Cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ if (NvidiaVideoCodec_ROOT)
endif ()

add_subdirectory(FeatureDetectors)

add_subdirectory(TensorRT)
31 changes: 31 additions & 0 deletions cpp/src/DO/Shakti/Cuda/TensorRT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if(NOT CMAKE_CUDA_COMPILER OR NOT TensorRT_FOUND)
return()
endif()

add_library(
DO_Shakti_Cuda_TensorRT #
Helpers.hpp #
IO.hpp #
IO.cpp #
InferenceExecutor.hpp #
InferenceExecutor.cpp #
DarknetParser.hpp #
DarknetParser.cpp #
Yolo.cpp
Yolo.hpp
YoloImpl.hpp
YoloImpl.cu)
add_library(DO::Shakti::Cuda::TensorRT ALIAS DO_Shakti_Cuda_TensorRT)
if(SARA_BUILD_SHARED_LIBS)
target_compile_definitions(DO_Shakti_Cuda_TensorRT PRIVATE DO_SARA_EXPORTS)
else()
target_compile_definitions(DO_Shakti_Cuda_TensorRT PUBLIC DO_SARA_STATIC)
endif()

target_link_libraries(
DO_Shakti_Cuda_TensorRT
PUBLIC $<$<PLATFORM_ID:Linux>:CUDA::cudart> #
TensorRT::TensorRT #
DO::Shakti::Cuda::Utilities #
DO::Sara::Darknet)
set_property(TARGET DO_Shakti_Cuda_TensorRT PROPERTY FOLDER "Libraries/Shakti")
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/Darknet/Parser.hpp>
#include <drafts/NeuralNetworks/TensorRT/DarknetParser.hpp>
#include <drafts/NeuralNetworks/TensorRT/IO.hpp>
#include <DO/Shakti/Cuda/TensorRT/DarknetParser.hpp>
#include <DO/Shakti/Cuda/TensorRT/IO.hpp>

#include <DO/Sara/NeuralNetworks/Darknet/Parser.hpp>


namespace DO::Sara::TensorRT {
using nvinfer1::IPluginV2;


static inline auto shape(const nvinfer1::ITensor& t) -> Eigen::Vector4i
{
Expand Down Expand Up @@ -293,7 +296,7 @@ namespace DO::Sara::TensorRT {

// Create the YOLO plugin.
const auto yolo_plugin =
std::unique_ptr<nvinfer1::IPluginV2, decltype(delete_plugin)>{
std::unique_ptr<IPluginV2, decltype(delete_plugin)>{
yolo_plugin_creator->createPlugin("", &fc), delete_plugin};
assert(yolo_plugin.get() != nullptr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#pragma once

#include <drafts/NeuralNetworks/Darknet/Network.hpp>
#include <drafts/NeuralNetworks/TensorRT/Helpers.hpp>
#include <drafts/NeuralNetworks/TensorRT/Yolo.hpp>
#include <DO/Shakti/Cuda/TensorRT/Helpers.hpp>
#include <DO/Shakti/Cuda/TensorRT/Yolo.hpp>

#include <DO/Sara/Core/DebugUtilities.hpp>
#include <DO/Sara/NeuralNetworks/Darknet/Network.hpp>

#include <NvInfer.h>

Expand Down Expand Up @@ -59,7 +59,8 @@ namespace DO::Sara::TensorRT {
std::vector<nvinfer1::ITensor*>& fmaps) const -> void;

auto add_maxpool_layer(const int layer_idx,
std::vector<nvinfer1::ITensor*>& fmaps) const -> void;
std::vector<nvinfer1::ITensor*>& fmaps) const
-> void;

auto add_upsample_layer(const int layer_idx,
std::vector<nvinfer1::ITensor*>& fmaps) const
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <drafts/NeuralNetworks/TensorRT/Helpers.hpp>
#include <DO/Shakti/Cuda/TensorRT/Helpers.hpp>


namespace DO::Sara::TensorRT {
Expand Down
Loading

0 comments on commit 6ce3fe4

Please sign in to comment.