From a21aa5f9f62879d0f13bd41ae7cb7b713c838938 Mon Sep 17 00:00:00 2001 From: "davidr@beechwoods.com" Date: Fri, 31 Mar 2023 17:57:24 -0400 Subject: [PATCH 01/10] Changes for ros2 humble --- ros2-tensorflow/ros2_tensorflow/CMakeLists.txt | 2 +- ros2-tensorflow/ros2_tf_core/setup.cfg | 4 ++-- ros2-tensorflow/tf_classification_py/setup.cfg | 4 ++-- .../tf_classification_py/classification_node.py | 2 +- ros2-tensorflow/tf_detection_py/setup.cfg | 4 ++-- .../tf_detection_py/tf_detection_py/detection_node.py | 10 ++++------ .../tf_detection_py/examples/client_test.py | 2 +- ros2-tensorflow/tf_interfaces/CMakeLists.txt | 3 +-- .../tf_interfaces/srv/ImageClassification.srv | 2 +- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ros2-tensorflow/ros2_tensorflow/CMakeLists.txt b/ros2-tensorflow/ros2_tensorflow/CMakeLists.txt index ca21990..cc3c411 100644 --- a/ros2-tensorflow/ros2_tensorflow/CMakeLists.txt +++ b/ros2-tensorflow/ros2_tensorflow/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.8) project(ros2_tensorflow) if(NOT CMAKE_CXX_STANDARD) diff --git a/ros2-tensorflow/ros2_tf_core/setup.cfg b/ros2-tensorflow/ros2_tf_core/setup.cfg index 25e4a81..63d2131 100644 --- a/ros2-tensorflow/ros2_tf_core/setup.cfg +++ b/ros2-tensorflow/ros2_tf_core/setup.cfg @@ -1,4 +1,4 @@ [develop] -script-dir=$base/lib/ros2_tf_core +script_dir=$base/lib/ros2_tf_core [install] -install-scripts=$base/lib/ros2_tf_core \ No newline at end of file +install_scripts=$base/lib/ros2_tf_core \ No newline at end of file diff --git a/ros2-tensorflow/tf_classification_py/setup.cfg b/ros2-tensorflow/tf_classification_py/setup.cfg index 5450b0a..dcea27f 100644 --- a/ros2-tensorflow/tf_classification_py/setup.cfg +++ b/ros2-tensorflow/tf_classification_py/setup.cfg @@ -1,4 +1,4 @@ [develop] -script-dir=$base/lib/tf_classification_py +script_dir=$base/lib/tf_classification_py [install] -install-scripts=$base/lib/tf_classification_py +install_scripts=$base/lib/tf_classification_py diff --git a/ros2-tensorflow/tf_classification_py/tf_classification_py/classification_node.py b/ros2-tensorflow/tf_classification_py/tf_classification_py/classification_node.py index 7bc8ed5..d5a4d81 100644 --- a/ros2-tensorflow/tf_classification_py/tf_classification_py/classification_node.py +++ b/ros2-tensorflow/tf_classification_py/tf_classification_py/classification_node.py @@ -101,7 +101,7 @@ def handle_image_classification_srv(self, request, response): response.classification.results = [] for i in range(len(classes)): hypotesis = ObjectHypothesis() - hypotesis.id = classes[i].item() + hypotesis.class_id = str(classes[i].item()) hypotesis.score = scores[i].item() response.classification.results.append(hypotesis) diff --git a/ros2-tensorflow/tf_detection_py/setup.cfg b/ros2-tensorflow/tf_detection_py/setup.cfg index bd9c15d..f55a33f 100644 --- a/ros2-tensorflow/tf_detection_py/setup.cfg +++ b/ros2-tensorflow/tf_detection_py/setup.cfg @@ -1,5 +1,5 @@ [develop] -script-dir=$base/lib/tf_detection_py +script_dir=$base/lib/tf_detection_py [install] -install-scripts=$base/lib/tf_detection_py \ No newline at end of file +install_scripts=$base/lib/tf_detection_py \ No newline at end of file diff --git a/ros2-tensorflow/tf_detection_py/tf_detection_py/detection_node.py b/ros2-tensorflow/tf_detection_py/tf_detection_py/detection_node.py index fcac191..d586456 100644 --- a/ros2-tensorflow/tf_detection_py/tf_detection_py/detection_node.py +++ b/ros2-tensorflow/tf_detection_py/tf_detection_py/detection_node.py @@ -169,24 +169,22 @@ def create_detections_msg(self, image_np, output_dict): det.header = detections.header det.results = [] detected_object = ObjectHypothesisWithPose() - detected_object.id = str(classes[i].item()) - detected_object.score = scores[i].item() + detected_object.hypothesis.class_id = str(classes[i].item()) + detected_object.hypothesis.score = scores[i].item() det.results.append(detected_object) # box is ymin, xmin, ymax, xmax in normalized coordinates box = boxes[i] det.bbox.size_y = (box[2] - box[0]) * img_height det.bbox.size_x = (box[3] - box[1]) * img_width - det.bbox.center.x = (box[1] + box[3]) * img_height / 2 - det.bbox.center.y = (box[0] + box[2]) * img_width / 2 + det.bbox.center.position.x = (box[1] + box[3]) * img_height / 2 + det.bbox.center.position.y = (box[0] + box[2]) * img_width / 2 if (self.republish_image): box_img = image_np[ int(box[0]*img_height):int(box[2]*img_height), int(box[1]*img_width):int(box[3]*img_width)] - det.source_img = img_utils.image_np_to_image_msg(box_img) - detections.detections.append(det) return detections diff --git a/ros2-tensorflow/tf_detection_py/tf_detection_py/examples/client_test.py b/ros2-tensorflow/tf_detection_py/tf_detection_py/examples/client_test.py index 467cc57..0b0d4a7 100644 --- a/ros2-tensorflow/tf_detection_py/tf_detection_py/examples/client_test.py +++ b/ros2-tensorflow/tf_detection_py/tf_detection_py/examples/client_test.py @@ -51,7 +51,7 @@ def vision_info_callback(vision_info_msg): for det in detections: det_result = det.results[0] node.get_logger().info( - f'Detected object {det_result.id} with score {det_result.score}') + f'Detected object {det_result.hypothesis.class_id} with score {det_result.hypothesis.score}') else: node.get_logger().error(f'Exception while calling service: {future.exception()}') diff --git a/ros2-tensorflow/tf_interfaces/CMakeLists.txt b/ros2-tensorflow/tf_interfaces/CMakeLists.txt index ee7c9a8..1a86eeb 100644 --- a/ros2-tensorflow/tf_interfaces/CMakeLists.txt +++ b/ros2-tensorflow/tf_interfaces/CMakeLists.txt @@ -1,5 +1,4 @@ -cmake_minimum_required(VERSION 3.5) - +cmake_minimum_required(VERSION 3.8) project(tf_interfaces) # Default to C++14 diff --git a/ros2-tensorflow/tf_interfaces/srv/ImageClassification.srv b/ros2-tensorflow/tf_interfaces/srv/ImageClassification.srv index d21c4d2..0cb3c68 100644 --- a/ros2-tensorflow/tf_interfaces/srv/ImageClassification.srv +++ b/ros2-tensorflow/tf_interfaces/srv/ImageClassification.srv @@ -1,3 +1,3 @@ sensor_msgs/Image image --- -vision_msgs/Classification2D classification \ No newline at end of file +vision_msgs/Classification classification \ No newline at end of file From 4115ee4e77c893047ad6bb9986e585d44268ca6d Mon Sep 17 00:00:00 2001 From: beechwoods-software <53622569+beechwoods-software@users.noreply.github.com> Date: Mon, 3 Apr 2023 09:02:42 -0400 Subject: [PATCH 02/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8dabbea..d931bb6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The output can be directly visualized through Rviz In order to build the `ros2-tensorflow` package, the following dependencies are needed Required dependencies: - - [ROS2 Foxy](https://docs.ros.org/en/foxy/Installation.html) + - [ROS2 Humble](https://docs.ros.org/en/humble/Installation.html) Rosdep dependencies: - [OpenCV Python](https://pypi.org/project/opencv-python/) From bb1f4f2214d188fe9d67f8eed4aa9aa3eea865f2 Mon Sep 17 00:00:00 2001 From: Dave Rensberger Date: Mon, 3 Apr 2023 16:28:43 -0400 Subject: [PATCH 03/10] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d931bb6..8a56bec 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,12 @@ Get the source code and create the ROS 2 workspace Install required dependencies using rosdep - $ rosdep install --from-paths src --ignore-src --rosdistro foxy -y + $ rosdep install --from-paths src --ignore-src --rosdistro humble -y Install the Tensorflow Object Detection Models (optional). Make sure to specify the correct Python version according to your system. - $ sudo apt-get install -y protobuf-compiler python-lxml python-tk + $ sudo apt-get install -y protobuf-compiler python3-lxml python-tk $ pip install --user Cython contextlib2 jupyter matplotlib Pillow $ git clone https://github.com/tensorflow/models.git /usr/local/lib/python3.8/dist-packages/tensorflow/models $ cd usr/local/lib/python3.8/dist-packages/tensorflow/models/research From ebfa4dc29bcee83ccfc97a775e133a96748c4507 Mon Sep 17 00:00:00 2001 From: Dave Rensberger Date: Mon, 3 Apr 2023 16:45:52 -0400 Subject: [PATCH 04/10] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a56bec..86dfde3 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,12 @@ Make sure to specify the correct Python version according to your system. $ sudo apt-get install -y protobuf-compiler python3-lxml python-tk $ pip install --user Cython contextlib2 jupyter matplotlib Pillow - $ git clone https://github.com/tensorflow/models.git /usr/local/lib/python3.8/dist-packages/tensorflow/models - $ cd usr/local/lib/python3.8/dist-packages/tensorflow/models/research - $ protoc object_detection/protos/*.proto --python_out=. + $ PYTHONDIRNAME=`python3 --version | awk -F ' ' '{ print $2 }' | awk -F . '{ print "python" $1 "." $2 }'` + $ sudo git clone https://github.com/tensorflow/models.git /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models + $ cd usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research + $ sudo protoc object_detection/protos/*.proto --python_out=. $ - $ echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/dist-packages/tensorflow/models/research' >> $HOME/.bashrc + $ echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research' >> $HOME/.bashrc Install Tensorflow Slim (optional) From ce67721672f76b382233b4af5da9462bcf71f2ec Mon Sep 17 00:00:00 2001 From: Dave Rensberger Date: Mon, 3 Apr 2023 16:52:22 -0400 Subject: [PATCH 05/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86dfde3..8d312d1 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Make sure to specify the correct Python version according to your system. $ cd usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research $ sudo protoc object_detection/protos/*.proto --python_out=. $ - $ echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research' >> $HOME/.bashrc + $ echo "export PYTHONPATH=\$PYTHONPATH:/usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research" >> $HOME/.bashrc Install Tensorflow Slim (optional) From 66a69c27a1d4e5396b04d4deb4eb4832b12c4c85 Mon Sep 17 00:00:00 2001 From: Dave Rensberger Date: Mon, 3 Apr 2023 17:22:53 -0400 Subject: [PATCH 06/10] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d312d1..a041c26 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,10 @@ Make sure to specify the correct Python version according to your system. $ sudo apt-get install -y protobuf-compiler python3-lxml python-tk $ pip install --user Cython contextlib2 jupyter matplotlib Pillow $ PYTHONDIRNAME=`python3 --version | awk -F ' ' '{ print $2 }' | awk -F . '{ print "python" $1 "." $2 }'` - $ sudo git clone https://github.com/tensorflow/models.git /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models + $ sudo mkdir models; sudo chmod 757 models + $ git clone https://github.com/tensorflow/models.git /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models $ cd usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research - $ sudo protoc object_detection/protos/*.proto --python_out=. + $ protoc object_detection/protos/*.proto --python_out=. $ $ echo "export PYTHONPATH=\$PYTHONPATH:/usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research" >> $HOME/.bashrc From 1fe2affb2edcadca700ef176c00f133daec9c30f Mon Sep 17 00:00:00 2001 From: Dave Rensberger Date: Mon, 3 Apr 2023 17:23:25 -0400 Subject: [PATCH 07/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a041c26..147022d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Make sure to specify the correct Python version according to your system. $ PYTHONDIRNAME=`python3 --version | awk -F ' ' '{ print $2 }' | awk -F . '{ print "python" $1 "." $2 }'` $ sudo mkdir models; sudo chmod 757 models $ git clone https://github.com/tensorflow/models.git /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models - $ cd usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research + $ cd /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research $ protoc object_detection/protos/*.proto --python_out=. $ $ echo "export PYTHONPATH=\$PYTHONPATH:/usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research" >> $HOME/.bashrc From 80667149e2ade5d3f316ae3d612e497bec73b5ec Mon Sep 17 00:00:00 2001 From: Dave Rensberger Date: Tue, 4 Apr 2023 17:30:39 -0400 Subject: [PATCH 08/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 147022d..0032833 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,10 @@ Install required dependencies using rosdep $ rosdep install --from-paths src --ignore-src --rosdistro humble -y Install the Tensorflow Object Detection Models (optional). -Make sure to specify the correct Python version according to your system. $ sudo apt-get install -y protobuf-compiler python3-lxml python-tk $ pip install --user Cython contextlib2 jupyter matplotlib Pillow + $ pip3 install --upgrade protobuf==3.20.3 $ PYTHONDIRNAME=`python3 --version | awk -F ' ' '{ print $2 }' | awk -F . '{ print "python" $1 "." $2 }'` $ sudo mkdir models; sudo chmod 757 models $ git clone https://github.com/tensorflow/models.git /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models From f86c05a949f37edae0b3a40a7ddf4e267a629147 Mon Sep 17 00:00:00 2001 From: "davidr@beechwoods.com" Date: Wed, 5 Apr 2023 12:06:19 -0400 Subject: [PATCH 09/10] Changes for humble and Ubuntu 22.04 docker build --- docker/Dockerfile | 25 ++++++++++++++----------- docker/build.sh | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index f1dc242..6c0c04a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,7 @@ # @author Alberto Soragna (alberto dot soragna at gmail dot com) # @2018 -FROM osrf/ros:foxy-desktop +FROM osrf/ros:humble-desktop LABEL maintainer="alberto dot soragna at gmail dot com" # working directory @@ -22,7 +22,7 @@ RUN apt-get update && apt-get install -y \ gdb \ vim \ nano \ - python-dev \ + python3-dev \ python3-pip \ unzip @@ -63,7 +63,8 @@ RUN pip3 install -U \ pytest \ pytest-cov \ pytest-runner \ - setuptools + setuptools \ + protobuf==3.20.3 # install Fast-RTPS dependencies RUN apt-get install --no-install-recommends -y \ @@ -87,8 +88,9 @@ WORKDIR $HOME # https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md RUN apt-get install -y \ protobuf-compiler \ - python-lxml \ + python3-lxml \ python-tk + RUN pip install \ Cython \ contextlib2 \ @@ -99,10 +101,10 @@ RUN pip install \ # get tensorflow models repository # currently object detection is part of research models that are not available on releases, so we use master # TODO: check v2.20 WIP object detection https://github.com/tensorflow/models/tree/v2.2.0/official/vision/detection -RUN git clone https://github.com/tensorflow/models.git /usr/local/lib/python3.8/dist-packages/tensorflow/models +RUN git clone https://github.com/tensorflow/models.git /usr/local/lib/python3.10/dist-packages/tensorflow/models # protobuf compilation -WORKDIR /usr/local/lib/python3.8/dist-packages/tensorflow/models/research +WORKDIR /usr/local/lib/python3.10/dist-packages/tensorflow/models/research RUN protoc object_detection/protos/*.proto --python_out=. # Tensorflow-Slim (required for image segmentation) @@ -134,10 +136,11 @@ RUN apt-get update RUN mkdir -p $HOME/tf_ws/src ADD https://api.github.com/repos/alsora/ros2-tensorflow/git/refs/heads/master version.json -RUN git clone https://github.com/alsora/ros2-tensorflow $HOME/tf_ws/src/ros2-tensorflow +#RUN git clone https://github.com/alsora/ros2-tensorflow $HOME/tf_ws/src/ros2-tensorflow +RUN git clone https://github.com/beechwoods-software/ros2-tensorflow $HOME/tf_ws/src/ros2-tensorflow WORKDIR $HOME/tf_ws -RUN rosdep install --from-paths src --ignore-src --rosdistro foxy -y -RUN /bin/bash -c 'source /opt/ros/foxy/setup.sh; \ +RUN rosdep install --from-paths src --ignore-src --rosdistro humble -y +RUN /bin/bash -c 'source /opt/ros/humble/setup.sh; \ colcon build' #### SET ENVIRONMENT @@ -146,11 +149,11 @@ WORKDIR $HOME RUN echo ' \n\ echo "Sourcing ROS2 packages..." \n\ -source /opt/ros/foxy/setup.sh \n\ +source /opt/ros/humble/setup.sh \n\ source $HOME/tf_ws/install/local_setup.sh' >> $HOME/.bashrc RUN echo ' \n\ -export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/dist-packages/tensorflow/models/research' >> $HOME/.bashrc +export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.10/dist-packages/tensorflow/models/research' >> $HOME/.bashrc RUN echo ' \n\ alias python="python3"' >> $HOME/.bashrc diff --git a/docker/build.sh b/docker/build.sh index a45dd81..9c9d16a 100644 --- a/docker/build.sh +++ b/docker/build.sh @@ -11,5 +11,5 @@ else CLEAN_CMD="" fi -docker pull osrf/ros:foxy-desktop -docker build $CLEAN_CMD -t $IMG_NAME . \ No newline at end of file +docker pull osrf/ros:humble-desktop +docker build $CLEAN_CMD -t $IMG_NAME . From d1a82ec1ff80307e9198af9db61a03970cfa9f94 Mon Sep 17 00:00:00 2001 From: "davidr@beechwoods.com" Date: Wed, 5 Apr 2023 12:11:31 -0400 Subject: [PATCH 10/10] Make URL in Dockerfile point to to the maintainer's repository --- docker/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 6c0c04a..f903bb9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -136,8 +136,7 @@ RUN apt-get update RUN mkdir -p $HOME/tf_ws/src ADD https://api.github.com/repos/alsora/ros2-tensorflow/git/refs/heads/master version.json -#RUN git clone https://github.com/alsora/ros2-tensorflow $HOME/tf_ws/src/ros2-tensorflow -RUN git clone https://github.com/beechwoods-software/ros2-tensorflow $HOME/tf_ws/src/ros2-tensorflow +RUN git clone https://github.com/alsora/ros2-tensorflow $HOME/tf_ws/src/ros2-tensorflow WORKDIR $HOME/tf_ws RUN rosdep install --from-paths src --ignore-src --rosdistro humble -y RUN /bin/bash -c 'source /opt/ros/humble/setup.sh; \