Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Humble updates #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down Expand Up @@ -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)

Expand Down
22 changes: 12 additions & 10 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,7 @@ RUN apt-get update && apt-get install -y \
gdb \
vim \
nano \
python-dev \
python3-dev \
python3-pip \
unzip

Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ else
CLEAN_CMD=""
fi

docker pull osrf/ros:foxy-desktop
docker build $CLEAN_CMD -t $IMG_NAME .
docker pull osrf/ros:humble-desktop
docker build $CLEAN_CMD -t $IMG_NAME .
2 changes: 1 addition & 1 deletion ros2-tensorflow/ros2_tensorflow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(ros2_tensorflow)

if(NOT CMAKE_CXX_STANDARD)
Expand Down
4 changes: 2 additions & 2 deletions ros2-tensorflow/ros2_tf_core/setup.cfg
Original file line number Diff line number Diff line change
@@ -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
install_scripts=$base/lib/ros2_tf_core
4 changes: 2 additions & 2 deletions ros2-tensorflow/tf_classification_py/setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions ros2-tensorflow/tf_detection_py/setup.cfg
Original file line number Diff line number Diff line change
@@ -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
install_scripts=$base/lib/tf_detection_py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}')

Expand Down
3 changes: 1 addition & 2 deletions ros2-tensorflow/tf_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.5)

cmake_minimum_required(VERSION 3.8)
project(tf_interfaces)

# Default to C++14
Expand Down
2 changes: 1 addition & 1 deletion ros2-tensorflow/tf_interfaces/srv/ImageClassification.srv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sensor_msgs/Image image
---
vision_msgs/Classification2D classification
vision_msgs/Classification classification