diff --git a/.gitignore b/.gitignore index c067b61..e22337a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +requirements.txt + /models /test/data diff --git a/CMakeLists.txt b/CMakeLists.txt index e5c175b..7427ef3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.0.2) project(detic_ros) +option(DETIC_ROS_INSTALL_TORCH "Installing the pytorch when building" ON) + find_package(catkin REQUIRED COMPONENTS catkin_virtualenv std_msgs @@ -66,9 +68,16 @@ catkin_package( CATKIN_DEPENDS message_runtime ) +if(DETIC_ROS_INSTALL_TORCH) + set(REQUIREMENTS requirements_with_torch.txt) +else() + set(REQUIREMENTS requirements_without_torch.txt) +endif() + catkin_generate_virtualenv( PYTHON_INTERPRETER python3 CHECK_VENV FALSE + INPUT_REQUIREMENTS ${REQUIREMENTS} ) file(GLOB PYTHON_SCRIPTS node_script/*.py) diff --git a/l4t.Dockerfile b/l4t.Dockerfile new file mode 100644 index 0000000..eecca97 --- /dev/null +++ b/l4t.Dockerfile @@ -0,0 +1,39 @@ +FROM nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.11-py3 + +ENV DEBIAN_FRONTEND=noninteractive + +# Remove OpenCV built with CUDA by NVIDIA. It conflicts with original OpenCV deb +RUN apt purge opencv-* -y + +# Install ROS +RUN apt update && apt install -y -qq curl &&\ + sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list' &&\ + curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - &&\ + apt update && apt install -y -qq \ + python3-catkin-tools python3-rosdep ros-noetic-desktop-full ros-noetic-jsk-recognition &&\ + rm -rf /var/lib/apt/lists/* + +# Upgrade pip-setup related packages to make grpcio install faster. Without this line, the grpcio would be compiled from source and it takes so much time. +RUN pip3 install --upgrade pip 'setuptools<=68.2.2' wheel && rm -rf ~/.cache/pip + +# Build detectron2 from source. The aarch64 version is not released +RUN cd /tmp &&\ + git clone --depth 1 -b v0.6 https://github.com/facebookresearch/detectron2 &&\ + pip3 install --no-cache-dir -e detectron2 &&\ + rm -rf ~/.cache/pip + +# Copy repository and install system dependencies +RUN rosdep init +RUN mkdir -p /catkin_ws/src/detic_ros +COPY package.xml /catkin_ws/src/detic_ros +RUN cd /catkin_ws/src/detic_ros &&\ + apt update &&\ + rosdep update &&\ + rosdep install --rosdistro=noetic -iqry --from-paths /catkin_ws/src &&\ + rm -rf /var/lib/apt/lists/* + +# Build +COPY . /catkin_ws/src/detic_ros +RUN sed -i '1,3d' /catkin_ws/src/detic_ros/requirements_without_torch.txt +RUN cd /catkin_ws &&\ + /opt/ros/noetic/env.sh catkin build detic_ros --cmake-args -DDETIC_ROS_INSTALL_TORCH=OFF diff --git a/prepare.sh b/prepare.sh index da4ae40..a4e794b 100755 --- a/prepare.sh +++ b/prepare.sh @@ -1,8 +1,6 @@ #!/usr/bin/bash -git submodule update --init --recursive - -ln -sf Detic/configs detic_configs +ln -sf Detic/configs detic_configs ln -sf Detic/datasets datasets cd node_script diff --git a/requirements.txt b/requirements_with_torch.txt similarity index 100% rename from requirements.txt rename to requirements_with_torch.txt diff --git a/requirements_without_torch.txt b/requirements_without_torch.txt new file mode 100644 index 0000000..1ed3dd9 --- /dev/null +++ b/requirements_without_torch.txt @@ -0,0 +1,17 @@ +-f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html +detectron2 + +pillow<10.0.0 # After 10.0.0, following error occurs: AttributeError: module 'PIL.Image' has no attribute 'LINEAR' + +# Copied from Detic +opencv-python==4.5.5.62 +timm==0.5.4 +dataclasses # remove version specification for local install +ftfy==6.0.3 +regex==2022.1.18 +fasttext==0.9.2 +scikit-learn==1.0.2 +numpy==1.22.0 +lvis==0.5.3 +nltk==3.6.7 +git+https://github.com/openai/CLIP.git