This is a ROS package for 2D object detection, which simply utilizes the toolbox MMDetection of OpenMMLab.
- ROS Melodic
- Python 3.6+, PyTorch 1.3+, CUDA 9.2+ and MMCV
-
Clone all needed packages: this package, mmdetection and vision_msgs
cd {YOUR WORKSPACE}/src git clone https://github.com/afengisme11/mmdetection_ros.git git clone https://github.com/ros-perception/vision_msgs.git cd mmdetection_ros git clone https://github.com/open-mmlab/mmdetection.git
-
MMDetection is a toolbox for 2D object detection. For using it I used a virtual environment in python3
sudo apt-get install python-pip python-dev python-virtualenv virtualenv --system-site-packages --python=python3 ~/mmdet source ~/mmdet/bin/activate pip --version # check the pip version
-
In this created environment we install all the requirements. Note that the following instructions for mmdetection are almost the same to the official one here, so you may also firstly have a look there if you have problems.
pip install mmdet
-
Then install PyTorch and torchvision following the official instructions here or for previous version here, e.g., I use CUDA 10.2 and install PyTorch 1.7.1, so I run this command:
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2
-
Install mmcv-full.
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
Check the table here. Please replace
{cu_version}
and{torch_version}
in the url to your desired one. For example, I use the following command:pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.7.0/index.html
-
Install build requirements and then install MMDetection.
cd ./mmdetection pip install -r requirements/build.txt pip install -v -e .
-
Install rospkg.
pip install rospkg
-
Put your model in the
scripts
folder, and modify the model path and config path in themmdetector.py
. The default one now is a Faster R-CNN I trained on my custom dataset to detect 5 products in the robot TIAGo context. You can also get it here if you want
~publish_rate
: the debug image publish rate. default: 1hz~is_service
: whether or not to use service instead of subscribe-publish~visualization
: whether or not to show the debug image
~debug_image
: publish the debug image~objects
: publish the inference result, containing the information of detected objects~image
: subscribe the input image. The default one is ''/xtion/rgb/image_raw' for TIAGo
If you are using the robot TIAGo, you could
source ~/mmdet/bin/activate # in the python3 virtual env
roslaunch mmdetection_ros mmdetector.launch
TIAGo will continously do the inference on the camera image and publish the detection results