Skip to content

Commit

Permalink
Enable to build the package in normal catkin workspace (#58)
Browse files Browse the repository at this point in the history
* Enabling catkin_virtualenv to build the package in normal catkin workspace

* restore docker usage

* fix cmake logic

* [format] isort

* temporary disable mypy test due to symlink submodules

* [CI] try cleaning up GA environment
  • Loading branch information
mqcmd196 authored Feb 5, 2025
1 parent 7f3419e commit eb8fbbb
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 57 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,49 @@ jobs:
name: test docker build
runs-on: ubuntu-latest
steps:
- name: Free disk space
run: |
sudo rm -rf "/opt/ghc" || true
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
sudo apt purge -y \
ansible* \
aria2* \
aspnetcore* \
azure-cli* \
cabal* \
clang* \
dotnet-* \
firefox* \
gfortran-* \
ghc* \
google-chrome-stable* \
google-cloud-sdk* \
imagemagick* \
javascript* \
kubectl* \
llvm* \
mono* \
mysql* \
nginx* \
node* \
npm* \
nuget* \
php* \
postgresql* \
powershell* \
rpm* \
ruby* \
sqlite3* \
subversion \
temurin* \
tmux* \
vim* \
yarn*
sudo apt-get autoremove -y >/dev/null 2>&1 || true
sudo apt-get autoclean -y >/dev/null 2>&1 || true
- name: Checkout
uses: actions/checkout@v2
- name: Setup QEMU
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/peripheral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ jobs:
- name: pip install formatters and mypy
run: |
pip3 install mypy flake8 isort
# Temporary commented out due to avoid testing submodule packages
# TODO (HiroIshida) fix
# - name: check by mypy
# run: |
# pip3 install -r requirements.txt
# pip3 install numpy==1.23 # to enable numpy's type checking
# mypy --version
# mypy .

- name: check by mypy
run: |
pip3 install -r requirements.txt
pip3 install numpy==1.23 # to enable numpy's type checking
mypy --version
mypy .
- name: check by isrot and flake8
- name: check by isort and flake8
run: |
python3 -m isort example/ test/ node_script/
python3 -m flake8 example/ test/ node_script/
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/models
/node_script/third_party
/node_script/detic
/test/data

# Byte-compiled / optimized / DLL files
Expand Down
59 changes: 58 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
cmake_minimum_required(VERSION 3.0.2)
project(detic_ros)

find_package(catkin REQUIRED
find_package(catkin REQUIRED COMPONENTS
catkin_virtualenv
std_msgs
sensor_msgs
message_generation
)

find_program(NVIDIA_SMI nvidia-smi)
if(NOT NVIDIA_SMI)
message(WARNING "NVIDIA Driver not found. It is strongly recommended that the NVIDIA GPU is available")
endif()

find_package(Git REQUIRED)
if ((NOT EXISTS ${PROJECT_SOURCE_DIR}/Detic/third_party/CenterNet2)
OR (NOT EXISTS ${PROJECT_SOURCE_DIR}/Detic/third_party/Deformable-DETR))
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endif()

catkin_python_setup()

find_package(Wget REQUIRED)
add_custom_target(create_models_dir
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_SOURCE_DIR}/models"
)
add_custom_target(download_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x ALL
DEPENDS create_models_dir
COMMAND ${WGET_EXECUTABLE} "https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth" -O "${PROJECT_SOURCE_DIR}/models/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth"
)
add_custom_target(download_LCOCOI21k_CLIP_CXT21k_640b32_4x_ft4x ALL
DEPENDS create_models_dir
COMMAND ${WGET_EXECUTABLE} "https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_CXT21k_640b32_4x_ft4x_max-size.pth" -O "${PROJECT_SOURCE_DIR}/models/Detic_LCOCOI21k_CLIP_CXT21k_640b32_4x_ft4x_max-size.pth"
)
add_custom_target(download_LCOCOI21k_CLIP_R5021k_640b32_4x_ft4x ALL
DEPENDS create_models_dir
COMMAND ${WGET_EXECUTABLE} "https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_R5021k_640b32_4x_ft4x_max-size.pth" -O "${PROJECT_SOURCE_DIR}/models/Detic_LCOCOI21k_CLIP_R5021k_640b32_4x_ft4x_max-size.pth"
)
add_custom_target(download_LCOCOI21k_CLIP_R18_640b32_4x_ft4x ALL
DEPENDS create_models_dir
COMMAND ${WGET_EXECUTABLE} "https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_R18_640b32_4x_ft4x_max-size.pth" -O "${PROJECT_SOURCE_DIR}/models/Detic_LCOCOI21k_CLIP_R18_640b32_4x_ft4x_max-size.pth"
)

add_message_files(
FILES
SegmentationInfo.msg
Expand All @@ -23,6 +61,25 @@ generate_messages(
std_msgs
sensor_msgs
)

catkin_package(
CATKIN_DEPENDS message_runtime
)

catkin_generate_virtualenv(
PYTHON_INTERPRETER python3
CHECK_VENV FALSE
)

file(GLOB PYTHON_SCRIPTS node_script/*.py)
catkin_install_python(
PROGRAMS ${PYTHON_SCRIPTS}
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(FILES requirements.txt
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

if(CATKIN_ENABLE_TESTING)
add_custom_target(${PROJECT_NAME}_download_image ALL
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ USER user
CMD /bin/bash
SHELL ["/bin/bash", "-c"]

RUN sudo apt install python3-pip -y
RUN pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

########################################
########### WORKSPACE BUILD ############
########################################
Expand Down
1 change: 1 addition & 0 deletions datasets
1 change: 1 addition & 0 deletions detic_configs
4 changes: 2 additions & 2 deletions example/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
import argparse

import cv2
import matplotlib.pyplot as plt
import rospy
from cv_bridge import CvBridge

from detic_ros.srv import DeticSeg

import cv2

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-image', type=str, help='input image path')
Expand Down
3 changes: 1 addition & 2 deletions example/masked_image_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import numpy as np
import rospy
from cv_bridge import CvBridge
from sensor_msgs.msg import Image

from detic_ros.msg import SegmentationInfo
from sensor_msgs.msg import Image


class SampleNode:
Expand Down
3 changes: 2 additions & 1 deletion node_script/batch_processor.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import rosbag
import tqdm
from cv_bridge import CvBridge
from sensor_msgs.msg import Image

from moviepy.editor import ImageSequenceClip
from node_config import NodeConfig
from sensor_msgs.msg import Image
from wrapper import DeticWrapper, InferenceRawResult


Expand Down
1 change: 1 addition & 0 deletions node_script/detic
19 changes: 7 additions & 12 deletions node_script/node.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
from typing import Optional

import rospy
import torch
from detic_ros.msg import SegmentationInfo
from detic_ros.node_config import NodeConfig
from detic_ros.srv import (CustomVocabulary, CustomVocabularyRequest,
CustomVocabularyResponse, DeticSeg, DeticSegRequest,
DeticSegResponse)
from detic_ros.wrapper import DeticWrapper
from jsk_recognition_msgs.msg import LabelArray, VectorArray
from node_config import NodeConfig
from rospy import Publisher, Subscriber
from sensor_msgs.msg import Image
from std_srvs.srv import Empty, EmptyRequest, EmptyResponse
from wrapper import DeticWrapper

from detic_ros.msg import SegmentationInfo
from detic_ros.srv import (
CustomVocabulary,
CustomVocabularyRequest,
CustomVocabularyResponse,
DeticSeg,
DeticSegRequest,
DeticSegResponse,
)
import torch


class DeticRosNode:
Expand Down
1 change: 1 addition & 0 deletions node_script/third_party
11 changes: 10 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@
<license>MIT</license>
<author>Hirokazu Ishida</author>
<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend>python3-catkin-pkg-modules</buildtool_depend>.
<buildtool_depend>python3-catkin-pkg-modules</buildtool_depend>
<buildtool_depend>python3-setuptools</buildtool_depend>
<build_depend>catkin_virtualenv</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>wget</build_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>std_srvs</exec_depend>
<exec_depend>jsk_common</exec_depend>
<exec_depend>jsk_recognition_msgs</exec_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>python3-rospkg</exec_depend>

<test_depend>rostest</test_depend>
<test_depend>image_publisher</test_depend>

<export>
<pip_requirements>requirements.txt</pip_requirements>
</export>
</package>
17 changes: 0 additions & 17 deletions prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,3 @@ cd node_script
ln -sf ../Detic/detic
ln -sf ../Detic/third_party
cd ..

if [ ! -d "models" ]; then
mkdir models
# All real-time models
# https://github.com/facebookresearch/Detic/blob/main/docs/MODEL_ZOO.md#real-time-models

# Swin Transformer model
wget -q https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth -O models/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth
# ConvNet model
wget -q https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_CXT21k_640b32_4x_ft4x_max-size.pth -O models/Detic_LCOCOI21k_CLIP_CXT21k_640b32_4x_ft4x_max-size.pth
# Res50 model
wget -q https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_R5021k_640b32_4x_ft4x_max-size.pth -O models/Detic_LCOCOI21k_CLIP_R5021k_640b32_4x_ft4x_max-size.pth
# Res18 model
wget -q https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_R18_640b32_4x_ft4x_max-size.pth -O models/Detic_LCOCOI21k_CLIP_R18_640b32_4x_ft4x_max-size.pth
fi

pip3 install -r requirements.txt
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-f https://download.pytorch.org/whl/torch_stable.html
torch==1.9.0+cu111
torchvision==0.10.0+cu111
torchaudio==0.9.0

-f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html
detectron2

Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from catkin_pkg.python_setup import generate_distutils_setup
from setuptools import setup

d = generate_distutils_setup(
packages=['detic_ros'],
package_dir={'': 'src'}
)

setup(**d)
Empty file added src/detic_ros/__init__.py
Empty file.
10 changes: 5 additions & 5 deletions node_script/node_config.py → src/detic_ros/node_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import rospy
import torch

# Dirty but no way, because CenterNet2 is not package oriented
sys.path.insert(0, os.path.join(sys.path[0], 'third_party/CenterNet2/'))
# Dirty but no way, because CenterNet2, Detic is not package oriented
rospack = rospkg.RosPack()
pack_path = rospack.get_path("detic_ros")
sys.path.insert(0, os.path.join(pack_path, 'node_script/third_party/CenterNet2'))
sys.path.insert(0, os.path.join(pack_path, 'Detic'))

from centernet.config import add_centernet_config
from detectron2.config import get_cfg
Expand Down Expand Up @@ -60,8 +63,6 @@ def from_args(
assert device_name in ['cpu', 'cuda']
assert model_type in NodeConfig.model_names

pack_path = rospkg.RosPack().get_path('detic_ros')

model_name = NodeConfig.model_names[model_type]
default_detic_config_path = os.path.join(
pack_path, 'detic_configs',
Expand Down Expand Up @@ -119,7 +120,6 @@ def to_detectron_config(self):
cfg.MODEL.ROI_HEADS.ONE_CLASS_PER_PROPOSAL = True

# Maybe should edit detic_configs/Base-C2_L_R5021k_640b64_4x.yaml
pack_path = rospkg.RosPack().get_path('detic_ros')
cfg.MODEL.ROI_BOX_HEAD.CAT_FREQ_PATH = os.path.join(
pack_path, 'datasets/metadata/lvis_v1_train_cat_info.json')

Expand Down
2 changes: 1 addition & 1 deletion node_script/wrapper.py → src/detic_ros/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from detectron2.utils.visualizer import VisImage
from detic.predictor import VisualizationDemo
from jsk_recognition_msgs.msg import Label, LabelArray, VectorArray
from node_config import NodeConfig
from detic_ros.node_config import NodeConfig
from sensor_msgs.msg import Image
from std_msgs.msg import Header

Expand Down
3 changes: 1 addition & 2 deletions test/test_detic_ros_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import rospy
import rostest
from sensor_msgs.msg import Image

from detic_ros.msg import SegmentationInfo
from sensor_msgs.msg import Image


class TestNode(unittest.TestCase):
Expand Down

0 comments on commit eb8fbbb

Please sign in to comment.