From 29c072400f44b96b8a0f132fbdebf0fe33419aa8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 21 Jan 2025 16:23:19 +0100 Subject: [PATCH] Mixed updates and improvements. --- README.md | 12 +++--- .../rpt2D_wrapper_cpp/src/rpt2D_wrapper.cpp | 12 +++--- rpt/triangulator.cpp | 29 +++++++------- scripts/.gitignore | 1 - scripts/test_skelda_dataset_cpp.cpp | 17 ++++---- scripts/test_skelda_dataset_cpp.py | 2 +- scripts/test_skelda_dataset_py.py | 10 ++--- scripts/utils_2d_pose.hpp | 40 ++----------------- scripts/utils_2d_pose.py | 1 + tests/.gitignore | 1 - tests/README.md | 6 +-- 11 files changed, 49 insertions(+), 82 deletions(-) delete mode 100644 scripts/.gitignore delete mode 100644 tests/.gitignore diff --git a/README.md b/README.md index 809c85b..169f5fb 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,16 @@ Fast triangulation of multiple persons from multiple camera views. cd /RapidPoseTriangulation/swig/ && make all && cd ../tests/ && python3 test_interface.py && cd .. cd /RapidPoseTriangulation/scripts/ && \ - g++ -std=c++17 -fPIC -O3 -march=native -Wall -Werror -flto=auto -fopenmp -fopenmp-simd \ - $(pkg-config --cflags opencv4) \ + g++ -std=c++2a -fPIC -O3 -march=native -Wall -Werror -flto=auto -fopenmp -fopenmp-simd \ -I /RapidPoseTriangulation/rpt/ \ - -I /onnxruntime/include/ \ - -I /onnxruntime/include/onnxruntime/core/session/ \ - -I /onnxruntime/include/onnxruntime/core/providers/tensorrt/ \ + -isystem /usr/include/opencv4/ \ + -isystem /onnxruntime/include/ \ + -isystem /onnxruntime/include/onnxruntime/core/session/ \ + -isystem /onnxruntime/include/onnxruntime/core/providers/tensorrt/ \ -L /onnxruntime/build/Linux/Release/ \ test_skelda_dataset_cpp.cpp \ /RapidPoseTriangulation/rpt/*.cpp \ - -o test_skelda_dataset \ + -o test_skelda_dataset.bin \ -Wl,--start-group \ -lonnxruntime_providers_tensorrt \ -lonnxruntime_providers_shared \ diff --git a/extras/ros/rpt2D_wrapper_cpp/src/rpt2D_wrapper.cpp b/extras/ros/rpt2D_wrapper_cpp/src/rpt2D_wrapper.cpp index f65f958..a8abc89 100644 --- a/extras/ros/rpt2D_wrapper_cpp/src/rpt2D_wrapper.cpp +++ b/extras/ros/rpt2D_wrapper_cpp/src/rpt2D_wrapper.cpp @@ -1,12 +1,12 @@ +#include #include +#include +#include #include +#include #include #include #include -#include -#include -#include -#include // ROS2 #include @@ -14,15 +14,15 @@ #include // OpenCV / cv_bridge -#include #include +#include // JSON library #include "/RapidPoseTriangulation/extras/include/nlohmann/json.hpp" using json = nlohmann::json; -#include "/RapidPoseTriangulation/scripts/utils_pipeline.hpp" #include "/RapidPoseTriangulation/scripts/utils_2d_pose.hpp" +#include "/RapidPoseTriangulation/scripts/utils_pipeline.hpp" // ================================================================================================= diff --git a/rpt/triangulator.cpp b/rpt/triangulator.cpp index f0d1662..91c1167 100644 --- a/rpt/triangulator.cpp +++ b/rpt/triangulator.cpp @@ -581,20 +581,21 @@ void TriangulatorInternal::reset() void TriangulatorInternal::print_stats() { - std::cout << "Triangulator statistics:" << std::endl; - std::cout << " Number of calls: " << num_calls << std::endl; - std::cout << " Init time: " << init_time / num_calls << std::endl; - std::cout << " Undistort time: " << undistort_time / num_calls << std::endl; - std::cout << " Project time: " << project_time / num_calls << std::endl; - std::cout << " Match time: " << match_time / num_calls << std::endl; - std::cout << " Pairs time: " << pairs_time / num_calls << std::endl; - std::cout << " Pair scoring time: " << pair_scoring_time / num_calls << std::endl; - std::cout << " Grouping time: " << grouping_time / num_calls << std::endl; - std::cout << " Full time: " << full_time / num_calls << std::endl; - std::cout << " Merge time: " << merge_time / num_calls << std::endl; - std::cout << " Post time: " << post_time / num_calls << std::endl; - std::cout << " Convert time: " << convert_time / num_calls << std::endl; - std::cout << " Total time: " << total_time / num_calls << std::endl; + std::cout << "{" << std::endl; + std::cout << " \"triangulator_calls\": " << num_calls << "," << std::endl; + std::cout << " \"init_time\": " << init_time / num_calls << "," << std::endl; + std::cout << " \"undistort_time\": " << undistort_time / num_calls << "," << std::endl; + std::cout << " \"project_time\": " << project_time / num_calls << "," << std::endl; + std::cout << " \"match_time\": " << match_time / num_calls << "," << std::endl; + std::cout << " \"pairs_time\": " << pairs_time / num_calls << "," << std::endl; + std::cout << " \"pair_scoring_time\": " << pair_scoring_time / num_calls << "," << std::endl; + std::cout << " \"grouping_time\": " << grouping_time / num_calls << "," << std::endl; + std::cout << " \"full_time\": " << full_time / num_calls << "," << std::endl; + std::cout << " \"merge_time\": " << merge_time / num_calls << "," << std::endl; + std::cout << " \"post_time\": " << post_time / num_calls << "," << std::endl; + std::cout << " \"convert_time\": " << convert_time / num_calls << "," << std::endl; + std::cout << " \"total_time\": " << total_time / num_calls << std::endl; + std::cout << "}" << std::endl; } // ================================================================================================= diff --git a/scripts/.gitignore b/scripts/.gitignore deleted file mode 100644 index efd6aff..0000000 --- a/scripts/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test_skelda_dataset diff --git a/scripts/test_skelda_dataset_cpp.cpp b/scripts/test_skelda_dataset_cpp.cpp index 7f45977..8e3bcaf 100644 --- a/scripts/test_skelda_dataset_cpp.cpp +++ b/scripts/test_skelda_dataset_cpp.cpp @@ -1,12 +1,12 @@ #include -#include -#include -#include #include -#include #include +#include +#include #include #include +#include +#include // OpenCV #include @@ -15,10 +15,10 @@ #include "/RapidPoseTriangulation/extras/include/nlohmann/json.hpp" using json = nlohmann::json; -#include "/RapidPoseTriangulation/scripts/utils_pipeline.hpp" -#include "/RapidPoseTriangulation/scripts/utils_2d_pose.hpp" -#include "/RapidPoseTriangulation/rpt/interface.hpp" #include "/RapidPoseTriangulation/rpt/camera.hpp" +#include "/RapidPoseTriangulation/rpt/interface.hpp" +#include "/RapidPoseTriangulation/scripts/utils_2d_pose.hpp" +#include "/RapidPoseTriangulation/scripts/utils_pipeline.hpp" // ================================================================================================= @@ -232,12 +232,12 @@ int main(int argc, char **argv) all_poses_3d.push_back(std::move(poses_3d)); all_ids.push_back(item["id"].get()); + old_id = item["index"]; } std::cout << std::endl; // Print timing stats std::cout << "\nMetrics:" << std::endl; - tri_model->print_stats(); size_t warmup = 10; double avg_time_image = time_image / (time_count - warmup); double avg_time_pose2d = time_pose2d / (time_count - warmup); @@ -249,6 +249,7 @@ int main(int argc, char **argv) << " \"avg_time_3d\": " << avg_time_pose3d << ",\n" << " \"fps\": " << fps << "\n" << "}" << std::endl; + tri_model->print_stats(); // Store the results as json json all_results; diff --git a/scripts/test_skelda_dataset_cpp.py b/scripts/test_skelda_dataset_cpp.py index 1fbdf9d..f601736 100644 --- a/scripts/test_skelda_dataset_cpp.py +++ b/scripts/test_skelda_dataset_cpp.py @@ -361,7 +361,7 @@ def main(): save_json(config, config_path) # Call the CPP binary - os.system("/RapidPoseTriangulation/scripts/test_skelda_dataset") + os.system("/RapidPoseTriangulation/scripts/test_skelda_dataset.bin") # Load the results print("Loading exports ...") diff --git a/scripts/test_skelda_dataset_py.py b/scripts/test_skelda_dataset_py.py index 00e8102..501d1a2 100644 --- a/scripts/test_skelda_dataset_py.py +++ b/scripts/test_skelda_dataset_py.py @@ -330,7 +330,9 @@ def main(): # Load 2D pose model if utils_pipeline.use_whole_body(whole_body): - kpt_model = utils_2d_pose.load_wb_model(min_bbox_score, min_bbox_area, batch_poses) + kpt_model = utils_2d_pose.load_wb_model( + min_bbox_score, min_bbox_area, batch_poses + ) else: kpt_model = utils_2d_pose.load_model(min_bbox_score, min_bbox_area, batch_poses) @@ -446,10 +448,7 @@ def main(): all_ids.append(label["id"]) times[i][2] = time_3d - # Print per-step triangulation timings - print("") - triangulator.print_stats() - + # Print per-step timings warmup_iters = 10 if len(times) > warmup_iters: times = times[warmup_iters:] @@ -464,6 +463,7 @@ def main(): } print("\nMetrics:") print(json.dumps(tstats, indent=2)) + triangulator.print_stats() _ = evals.mpjpe.run_eval( labels, diff --git a/scripts/utils_2d_pose.hpp b/scripts/utils_2d_pose.hpp index fa97ecb..b99a0ff 100644 --- a/scripts/utils_2d_pose.hpp +++ b/scripts/utils_2d_pose.hpp @@ -1,13 +1,13 @@ #pragma once #include -#include -#include #include +#include +#include -#include #include #include +#include #include // ================================================================================================= @@ -646,27 +646,10 @@ namespace utils_2d_pose std::vector> RTMDet::call(const cv::Mat &image) { - auto stime = std::chrono::high_resolution_clock::now(); - std::chrono::duration elapsed; - cv::Mat preprocessed = preprocess(image); std::vector inputs = {preprocessed}; - - elapsed = std::chrono::high_resolution_clock::now() - stime; - std::cout << "Preprocess time: " << elapsed.count() << "s\n"; - stime = std::chrono::high_resolution_clock::now(); - auto results = call_by_image(inputs); - - elapsed = std::chrono::high_resolution_clock::now() - stime; - std::cout << "Inference time: " << elapsed.count() << "s\n"; - stime = std::chrono::high_resolution_clock::now(); - auto outputs = postprocess(results, image); - - elapsed = std::chrono::high_resolution_clock::now() - stime; - std::cout << "Postprocess time: " << elapsed.count() << "s\n"; - return outputs; } @@ -818,26 +801,9 @@ namespace utils_2d_pose std::vector>> RTMPose::call( const cv::Mat &image, const std::vector> &bboxes) { - auto stime = std::chrono::high_resolution_clock::now(); - std::chrono::duration elapsed; - std::vector inputs = preprocess(image, bboxes); - - elapsed = std::chrono::high_resolution_clock::now() - stime; - std::cout << "Preprocess time: " << elapsed.count() << "s\n"; - stime = std::chrono::high_resolution_clock::now(); - auto results = call_by_image(inputs); - - elapsed = std::chrono::high_resolution_clock::now() - stime; - std::cout << "Inference time: " << elapsed.count() << "s\n"; - stime = std::chrono::high_resolution_clock::now(); - auto outputs = postprocess(results, image, bboxes); - - elapsed = std::chrono::high_resolution_clock::now() - stime; - std::cout << "Postprocess time: " << elapsed.count() << "s\n"; - return outputs; } diff --git a/scripts/utils_2d_pose.py b/scripts/utils_2d_pose.py index 7b364e3..601518d 100644 --- a/scripts/utils_2d_pose.py +++ b/scripts/utils_2d_pose.py @@ -20,6 +20,7 @@ class BaseModel(ABC): raise FileNotFoundError("File not found:", model_path) if model_path.endswith(".onnx"): + print("Loading model:", model_path) self.init_onnxruntime(model_path) self.runtime = "ort" else: diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index da9ca31..0000000 --- a/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -my_app diff --git a/tests/README.md b/tests/README.md index 83a3dc0..d6a791c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -13,14 +13,14 @@ Various module tests ```bash cd /RapidPoseTriangulation/tests/ -g++ -std=c++17 -O3 -march=native -Wall -DCOMPILE_EXAMPLE_MAIN \ +g++ -std=c++17 -O3 -march=native -Wall \ $(pkg-config --cflags opencv4) \ -I /onnxruntime/include \ -I /onnxruntime/include/onnxruntime/core/session \ -I /onnxruntime/include/onnxruntime/core/providers/tensorrt \ -L /onnxruntime/build/Linux/Release \ test_utils2d.cpp \ - -o my_app \ + -o my_app.bin \ -Wl,--start-group \ -lonnxruntime_providers_tensorrt \ -lonnxruntime_providers_shared \ @@ -30,5 +30,5 @@ g++ -std=c++17 -O3 -march=native -Wall -DCOMPILE_EXAMPLE_MAIN \ $(pkg-config --libs opencv4) \ -Wl,-rpath,/onnxruntime/build/Linux/Release -./my_app +./my_app.bin ```