diff --git a/README.md b/README.md index 8dabbea..0032833 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/) @@ -43,18 +43,20 @@ 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 + $ 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 + $ cd /usr/local/lib/$PYTHONDIRNAME/dist-packages/tensorflow/models/research $ 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) diff --git a/docker/Dockerfile b/docker/Dockerfile index f1dc242..f903bb9 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) @@ -136,8 +138,8 @@ 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 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 +148,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 . 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