Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit 05c8b7d

Browse files
Fix runtime on noetic and linux (#24)
* Fix runtime on noetic and linux * Fixup Doc Co-authored-by: Lou Amadio <[email protected]>
1 parent fff435f commit 05c8b7d

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
lines changed

README.md

+17-26
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,47 @@ ONNX Runtime Execution Providers (EPs) enables the execution of any ONNX model u
66
In simple terms, developers no longer need to worry about the nuances of hardware specific custom libraries to accelerate their machine learning models.
77
This repository demonstrates that by enabling the same code with ROS 2 to run on different hardware platforms using their respective AI acceleration libraries for optimized execution of the ONNX model.
88

9-
## System Requirement
9+
## Requirements
1010

1111
* Microsoft Windows 10 64-bit or Ubuntu 20.04 LTS x86_64
1212
* ROS Noetic
13-
* To make use of the hardware acceleration, the system is required to be compatible with [**CUDA 10.1**](https://developer.nvidia.com/cuda-toolkit) and [**cuDNN 7.6.5**](https://developer.nvidia.com/cudnn).
14-
15-
> For GPU support, please follow the installation steps on NVIDIA portal before proceeding.
13+
* GPU acceleration on Linux
14+
* [**CUDA 11**](https://developer.nvidia.com/cuda-toolkit)
15+
* [**cuDNN 8.x**](https://developer.nvidia.com/cudnn)
1616

1717
## How to Build
1818
The Onnx ROS Node is distrubted as source. To consume it in your robot, clone the ros_msft_onnx sources into your workspace.
1919

20-
* Windows
21-
```Batchfile
20+
### Windows
21+
Windows will automatically use dedicated ML hardware, GPU or CPU depending on the best combination for the running ML model.
22+
23+
```cmd
2224
mkdir c:\workspace\onnx_demo\src
2325
cd c:\workspace\onnx_demo\src
2426
git clone https://github.com/ms-iot/ros_msft_onnx -b noetic-devel
2527
2628
::For running the samples, clone `ros_msft_camera` as well
2729
git clone https://github.com/ms-iot/ros_msft_camera --recursive
30+
catkin_make
2831
```
2932

30-
* Ubuntu
31-
```sh
33+
### Ubuntu
34+
35+
```bash
3236
mkdir -p onnx_demo/src
3337
cd onnx_demo/src
3438
git clone https://github.com/ms-iot/ros_msft_onnx -b noetic-devel
3539

36-
#For running the samples, clone `ros_msft_camera` as well
40+
# For running the samples, clone `cv_camera` as well
3741
git clone https://github.com/OTL/cv_camera --recursive
38-
```
39-
40-
## Building
41-
ONNX Runtime team is releasing different binaries for CPU and GPU (CUDA) support. To switch between the two, a workspace rebuild is required.
42-
42+
cd ..
4343

44-
Make sure to source your ROS version before building.
45-
46-
* CPU Processing
47-
48-
```Batchfile
49-
cd onnx_demo
50-
51-
catkin_make -DCUDA_SUPPORT=OFF
44+
catkin_make
5245
```
5346

54-
* GPU Processing (CUDA)
55-
56-
```Batchfile
57-
cd onnx_demo
47+
If you would like to use CUDA support and have the software installed, you can build using the following command:
5848

49+
``` bash
5950
catkin_make -DCUDA_SUPPORT=ON
6051
```
6152

ros_msft_onnx/CMakeLists.txt

+18-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ generate_dynamic_reconfigure_options(
4747

4848
catkin_package(
4949
INCLUDE_DIRS include
50-
CATKIN_DEPENDS std_msgs geometry_msgs visualization_msgs ros_msft_onnx_msgs image_transport dynamic_reconfigure roscpp cv_bridge tf
50+
CATKIN_DEPENDS
51+
std_msgs
52+
geometry_msgs
53+
visualization_msgs
54+
ros_msft_onnx_msgs
55+
image_transport
56+
dynamic_reconfigure
57+
roscpp
58+
cv_bridge tf
5159
CFG_EXTRAS "onnxruntime_vendor-extras.cmake"
5260
)
5361

@@ -63,14 +71,18 @@ target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} ${OpenCV_LIBRARIE
6371

6472
message("Installing onnxruntime_vendor Nuget package")
6573

66-
if(CUDA_SUPPORT)
74+
if(MSVC)
75+
set(ONNX_RUNTIME "Microsoft.ML.OnnxRuntime.DirectML.1.7.0")
76+
set(PACKAGE_URL "https://www.nuget.org/api/v2/package/Microsoft.ML.OnnxRuntime.DirectML/1.7.0")
77+
set(PACKAGE_SHA512 "2e5bd2c0ade72444d4efdfbd6a75571aaa72045769f9b5847186129c9e5e667ad080d5d2b9a12cce88c9eee68302be89cdb7030ccefa3d572e591b1c453c7340")
78+
elseif(CUDA_SUPPORT)
6779
set(ONNX_RUNTIME "Microsoft.ML.OnnxRuntime.Gpu.1.7.1")
6880
set(PACKAGE_URL "https://www.nuget.org/api/v2/package/Microsoft.ML.OnnxRuntime.Gpu/1.7.1")
6981
set(PACKAGE_SHA512 "41112118007aae34fcc38100152df6e6fa5fc567e61aa4ded42a26d39751f1be7ec225c0d73799f065015e284f0fb9bd7e0835c733e9abad5b0243a391411f8d")
7082
else()
71-
set(ONNX_RUNTIME "Microsoft.ML.OnnxRuntime.DirectML.1.7.0")
72-
set(PACKAGE_URL "https://www.nuget.org/api/v2/package/Microsoft.ML.OnnxRuntime.DirectML/1.7.0")
73-
set(PACKAGE_SHA512 "2e5bd2c0ade72444d4efdfbd6a75571aaa72045769f9b5847186129c9e5e667ad080d5d2b9a12cce88c9eee68302be89cdb7030ccefa3d572e591b1c453c7340")
83+
set(ONNX_RUNTIME "Microsoft.ML.OnnxRuntime.1.7.0")
84+
set(PACKAGE_URL "https://www.nuget.org/api/v2/package/Microsoft.ML.OnnxRuntime/1.7.0")
85+
set(PACKAGE_SHA512 "1fc15386bdfa455f457e50899e3c9c454aafbdc345799dcf4ecfd6990a9dbd8cd7f0b1f3bf412c47c900543c535f95aa1cb1e14e9851cb9b600c60a981f38a50")
7486
endif()
7587

7688
file(DOWNLOAD
@@ -90,7 +102,7 @@ if(MSVC)
90102

91103
else()
92104
set(ARCH "linux-x64")
93-
execute_process(COMMAND unzip "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.nuget"
105+
execute_process(COMMAND unzip -oq "${CMAKE_CURRENT_BINARY_DIR}/onnxruntime.nuget"
94106
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${ONNX_RUNTIME}"
95107
)
96108

ros_msft_onnx/src/pose_parser.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include <ros/ros.h>
2-
#include <cv_bridge/cv_bridge.h>
3-
#include <image_transport/image_transport.h>
42
#include <visualization_msgs/MarkerArray.h>
5-
#include <opencv2/calib3d/calib3d.hpp>
63
#include <tf/LinearMath/Quaternion.h>
74
#include <tf/transform_datatypes.h>
5+
#include <cv_bridge/cv_bridge.h>
6+
#include <image_transport/image_transport.h>
7+
#include <opencv2/calib3d/calib3d.hpp>
88

99
#include "ros_msft_onnx/ros_msft_onnx.h"
1010
#include "ros_msft_onnx/pose_parser.h"
@@ -203,8 +203,8 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
203203

204204
if (_fake)
205205
{
206-
std::vector<visualization_msgs::Marker> markers;
207206
visualization_msgs::Marker marker;
207+
visualization_msgs::MarkerArray markers;
208208
marker.header.frame_id = _linkName;
209209
marker.header.stamp = ros::Time();
210210
marker.ns = "onnx";
@@ -234,7 +234,7 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
234234
marker.color.g = 0.0;
235235
marker.color.b = 1.0;
236236

237-
markers.push_back(marker);
237+
markers.markers.push_back(marker);
238238
_detect_pub.publish(markers);
239239
return;
240240
}
@@ -284,7 +284,7 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
284284
tf::Quaternion poseQuat;
285285
tfRod.getRotation(poseQuat);
286286

287-
std::vector<visualization_msgs::Marker> markers;
287+
visualization_msgs::MarkerArray markers;
288288
visualization_msgs::Marker marker;
289289
double x = tvec.at<double>(0) / 1000.0;
290290
double y = tvec.at<double>(1) / 1000.0;
@@ -294,7 +294,7 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
294294
marker.mesh_resource = meshResource;
295295

296296
tf::quaternionTFToMsg(poseQuat, marker.pose.orientation);
297-
markers.push_back(marker);
297+
markers.markers.push_back(marker);
298298

299299
ros_msft_onnx_msgs::DetectedObjectPose doPose;
300300

@@ -329,7 +329,7 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
329329

330330
marker1.color.r = 1.0; marker1.color.g = 0.0; marker1.color.b = 0.0;
331331
tf::quaternionTFToMsg(poseQuat, marker1.pose.orientation);
332-
markers.push_back(marker1);
332+
markers.markers.push_back(marker1);
333333

334334
visualization_msgs::Marker marker2;
335335
initMarker(marker2, 2, visualization_msgs::Marker::ARROW, x, y, z);
@@ -341,7 +341,7 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
341341

342342
marker2.color.r = 0.0; marker2.color.g = 1.0; marker2.color.b = 0.0;
343343
tf::quaternionTFToMsg(poseQuat, marker2.pose.orientation);
344-
markers.push_back(marker2);
344+
markers.markers.push_back(marker2);
345345

346346
visualization_msgs::Marker marker3;
347347
initMarker(marker3, 3, visualization_msgs::Marker::ARROW, x, y, z);
@@ -353,7 +353,7 @@ void PoseProcessor::ProcessOutput(std::vector<float> output, cv::Mat& image)
353353

354354
marker3.color.r = 0.0; marker3.color.g = 0.0; marker3.color.b = 1.0;
355355
tf::quaternionTFToMsg(poseQuat, marker3.pose.orientation);
356-
markers.push_back(marker3);
356+
markers.markers.push_back(marker3);
357357
}
358358

359359
_detect_pub.publish(markers);

ros_msft_onnx/src/yolo_box.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ros/ros.h>
2+
#include <visualization_msgs/MarkerArray.h>
23
#include <cv_bridge/cv_bridge.h>
34
#include <image_transport/image_transport.h>
4-
#include <visualization_msgs/MarkerArray.h>
55

66
#include "ros_msft_onnx/ros_msft_onnx.h"
77
#include "ros_msft_onnx/yolo_box.h"
@@ -77,8 +77,8 @@ namespace yolo
7777

7878
// If we found a person, send a message
7979
int count = 0;
80-
std::vector<visualization_msgs::Marker> markers;
81-
for (std::vector<YoloBox>::iterator it = boxes.begin(); it != boxes.end(); ++it)
80+
visualization_msgs::MarkerArray markers;
81+
for(std::vector<YoloBox>::iterator it = boxes.begin(); it != boxes.end(); ++it)
8282
{
8383
for (auto label : _labels)
8484
{
@@ -108,7 +108,7 @@ namespace yolo
108108
marker.color.g = 0.0;
109109
marker.color.b = 1.0;
110110

111-
markers.push_back(marker);
111+
markers.markers.push_back(marker);
112112

113113
if (_debug)
114114
{

0 commit comments

Comments
 (0)