Skip to content

Commit

Permalink
feat(tier4_perception_launch): enable to use multi camera on traffic …
Browse files Browse the repository at this point in the history
…light recognition (#8676)

* main process

Signed-off-by: MasatoSaeki <[email protected]>

* style(pre-commit): autofix

* add exception if input is invalid

Signed-off-by: MasatoSaeki <[email protected]>

---------

Signed-off-by: MasatoSaeki <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
MasatoSaeki and pre-commit-ci[bot] authored Sep 18, 2024
1 parent d57f82d commit edb4179
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 147 deletions.
4 changes: 2 additions & 2 deletions launch/tier4_perception_launch/launch/perception.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<arg name="use_traffic_light_recognition" default="false"/>
<arg name="traffic_light_recognition/enable_fine_detection" default="true"/>
<arg name="traffic_light_recognition/fusion_only" default="false"/>
<arg name="traffic_light_image_number" default="1" description="choose traffic light image raw number(1-2)"/>
<arg name="all_traffic_light_camera" default="[camera6, camera7]" description="choose camera which use for traffic light recognition"/>
<arg
name="traffic_light_fine_detector_model_path"
default="$(var data_path)/traffic_light_fine_detector"
Expand Down Expand Up @@ -294,7 +294,7 @@
<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light.launch.xml">
<arg name="enable_fine_detection" value="$(var traffic_light_recognition/enable_fine_detection)"/>
<arg name="fusion_only" value="$(var traffic_light_recognition/fusion_only)"/>
<arg name="image_number" value="$(var traffic_light_image_number)"/>
<arg name="all_camera_namespaces" value="$(var all_traffic_light_camera)"/>
<arg name="traffic_light_arbiter_param_path" value="$(var traffic_light_arbiter_param_path)"/>
<arg name="traffic_light_fine_detector_model_path" value="$(var traffic_light_fine_detector_model_path)"/>
<arg name="traffic_light_fine_detector_model_name" value="$(var traffic_light_fine_detector_model_name)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,139 +3,55 @@
<arg name="enable_image_decompressor" default="true" description="enable image decompressor"/>
<arg name="enable_fine_detection" default="true" description="enable fine position adjustment of traffic light"/>
<arg name="fusion_only" default="false" description="launch only occlusion_predictor and multi_camera_fusion"/>
<arg name="traffic_light_fine_detector_model_path" default="$(find-pkg-share autoware_traffic_light_fine_detector)/data" description="fine detector label path"/>
<arg name="traffic_light_fine_detector_label_name" default="tlr_labels.txt" description="fine detector label filename"/>
<arg name="traffic_light_fine_detector_model_name" default="tlr_yolox_s_batch_6" description="fine detector onnx model filename"/>
<arg name="traffic_light_classifier_model_path" default="$(find-pkg-share autoware_traffic_light_classifier)/data" description="classifier label path"/>
<arg name="car_traffic_light_classifier_label_name" default="lamp_labels.txt" description="classifier label filename"/>
<arg name="pedestrian_traffic_light_classifier_label_name" default="lamp_labels_ped.txt" description="classifier label filename"/>
<arg name="car_traffic_light_classifier_model_name" default="traffic_light_classifier_mobilenetv2_batch_6.onnx" description="classifier onnx model filename"/>
<arg name="pedestrian_traffic_light_classifier_model_name" default="ped_traffic_light_classifier_mobilenetv2_batch_6.onnx" description="classifier onnx model filename"/>
<arg name="input/cloud" default="/sensing/lidar/top/pointcloud_raw_ex" description="point cloud for occlusion prediction"/>
<arg name="judged/traffic_signals" default="/perception/traffic_light_recognition/judged/traffic_signals"/>
<arg name="internal/traffic_signals" default="/perception/traffic_light_recognition/internal/traffic_signals"/>
<arg name="external/traffic_signals" default="/perception/traffic_light_recognition/external/traffic_signals"/>
<arg name="output/traffic_signals" default="/perception/traffic_light_recognition/traffic_signals"/>
<arg name="use_crosswalk_traffic_light_estimator" default="true" description="output pedestrian's traffic light signals"/>
<arg name="crosswalk_traffic_light_estimator_param_file" default="$(find-pkg-share autoware_crosswalk_traffic_light_estimator)/config/crosswalk_traffic_light_estimator.param.yaml"/>
<arg name="image_number" default="1" description="choose image raw number(1-2)"/>
<arg name="namespace1" default="camera6"/>
<arg name="namespace2" default="camera7"/>
<let name="all_camera_namespaces" value="[$(var namespace1)]" if="$(eval &quot; '$(var image_number)' == '1' &quot;)"/>
<let name="all_camera_namespaces" value="[$(var namespace1), $(var namespace2)]" if="$(eval &quot; '$(var image_number)' >= '2' &quot;)"/>
<arg name="all_camera_namespaces" default="[camera6, camera7]"/>

<!-- ML parameters -->
<arg name="fine_detector_param_path" default="$(find-pkg-share autoware_traffic_light_fine_detector)/config/traffic_light_fine_detector.param.yaml"/>
<arg name="car_classifier_param_path" default="$(find-pkg-share autoware_traffic_light_classifier)/config/car_traffic_light_classifier.param.yaml"/>
<arg name="pedestrian_classifier_param_path" default="$(find-pkg-share autoware_traffic_light_classifier)/config/pedestrian_traffic_light_classifier.param.yaml"/>
<arg name="traffic_light_fine_detector_model_path" default="$(find-pkg-share autoware_traffic_light_fine_detector)/data" description="fine detector label path"/>
<arg name="traffic_light_fine_detector_model_name" default="tlr_yolox_s_batch_6" description="fine detector onnx model filename"/>
<arg name="traffic_light_fine_detector_label_name" default="tlr_labels.txt" description="fine detector label filename"/>
<arg name="traffic_light_classifier_model_path" default="$(find-pkg-share autoware_traffic_light_classifier)/data" description="classifier label path"/>
<arg name="car_traffic_light_classifier_label_name" default="lamp_labels.txt" description="classifier label filename"/>
<arg name="pedestrian_traffic_light_classifier_label_name" default="lamp_labels_ped.txt" description="classifier label filename"/>
<arg name="car_traffic_light_classifier_model_name" default="traffic_light_classifier_mobilenetv2_batch_6.onnx" description="classifier onnx model filename"/>
<arg name="pedestrian_traffic_light_classifier_model_name" default="ped_traffic_light_classifier_mobilenetv2_batch_6.onnx" description="classifier onnx model filename"/>

<!-- namespace1 camera TLR pipeline -->
<group>
<push-ros-namespace namespace="$(var namespace1)"/>
<let name="input/image" value="/sensing/camera/$(var namespace1)/image_raw"/>
<let name="input/camera_info" value="/sensing/camera/$(var namespace1)/camera_info"/>
<let name="output/rois1" value="/perception/traffic_light_recognition/$(var namespace1)/detection/rois"/>
<let name="output/traffic_signals1" value="/perception/traffic_light_recognition/$(var namespace1)/classification/traffic_signals"/>
<let name="output/car/traffic_signals1" value="/perception/traffic_light_recognition/$(var namespace1)/classification/car/traffic_signals"/>
<let name="output/pedestrian/traffic_signals1" value="/perception/traffic_light_recognition/$(var namespace1)/classification/pedestrian/traffic_signals"/>
<let name="map_based_detector_output_topic" value="rough/rois" if="$(var enable_fine_detection)"/>
<let name="map_based_detector_output_topic" value="$(var output/rois1)" unless="$(var enable_fine_detection)"/>

<group unless="$(var fusion_only)">
<node pkg="topic_tools" exec="relay" name="traffic_light_camera_info_relay" args="$(var input/camera_info) camera_info"/>
<group>
<push-ros-namespace namespace="detection"/>
<include file="$(find-pkg-share autoware_traffic_light_map_based_detector)/launch/traffic_light_map_based_detector.launch.xml">
<arg name="input/camera_info" value="$(var input/camera_info)"/>
<arg name="expect/rois" value="expect/rois"/>
<arg name="output/rois" value="$(var map_based_detector_output_topic)"/>
<!-- This parameter should be configured differently for each camera considering their delay. -->
<arg name="min_timestamp_offset" value="-0.3"/>
<arg name="max_timestamp_offset" value="0.0"/>
</include>
</group>

<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light_node_container.launch.py">
<arg name="input/image" value="$(var input/image)"/>
<arg name="enable_image_decompressor" value="$(var enable_image_decompressor)"/>
<arg name="enable_fine_detection" value="$(var enable_fine_detection)"/>
<arg name="use_intra_process" value="true"/>
<arg name="use_multithread" value="true"/>
<arg name="fine_detector_param_path" value="$(var fine_detector_param_path)"/>
<arg name="car_classifier_param_path" value="$(var car_classifier_param_path)"/>
<arg name="pedestrian_classifier_param_path" value="$(var pedestrian_classifier_param_path)"/>
<arg name="output/rois" value="$(var output/rois1)"/>
<arg name="output/traffic_signals" value="$(var output/traffic_signals1)"/>
<arg name="output/car/traffic_signals" value="$(var output/car/traffic_signals1)"/>
<arg name="output/pedestrian/traffic_signals" value="$(var output/pedestrian/traffic_signals1)"/>
</include>
</group>

<group>
<push-ros-namespace namespace="classification"/>
<include file="$(find-pkg-share autoware_traffic_light_occlusion_predictor)/launch/traffic_light_occlusion_predictor.launch.xml">
<arg name="input/camera_info" value="$(var input/camera_info)"/>
<arg name="input/cloud" value="$(var input/cloud)"/>
<arg name="input/rois" value="$(var output/rois1)"/>
<arg name="input/car/traffic_signals" value="classified/car/traffic_signals"/>
<arg name="input/pedestrian/traffic_signals" value="classified/pedestrian/traffic_signals"/>
<arg name="output/traffic_signals" value="$(var output/traffic_signals1)"/>
</include>
</group>
<!-- main TLR pipeline on each camera -->
<group unless="$(var fusion_only)">
<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light_camera_info_relay.launch.py">
<arg name="all_camera_namespaces" value="$(var all_camera_namespaces)"/>
</include>
<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light_map_based_detector.launch.py">
<arg name="all_camera_namespaces" value="$(var all_camera_namespaces)"/>
<arg name="enable_fine_detection" value="$(var enable_fine_detection)"/>
</include>
<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light_node_container.launch.py">
<arg name="all_camera_namespaces" value="$(var all_camera_namespaces)"/>
<arg name="enable_image_decompressor" value="$(var enable_image_decompressor)"/>
<arg name="enable_fine_detection" value="$(var enable_fine_detection)"/>
<arg name="use_intra_process" value="true"/>
<arg name="use_multithread" value="true"/>
<arg name="fine_detector_param_path" value="$(var fine_detector_param_path)"/>
<arg name="car_classifier_param_path" value="$(var car_classifier_param_path)"/>
<arg name="pedestrian_classifier_param_path" value="$(var pedestrian_classifier_param_path)"/>
</include>
</group>

<!-- namespace2 camera TLR pipeline -->
<group if="$(eval &quot; '$(var image_number)' >= '2' &quot;)">
<push-ros-namespace namespace="$(var namespace2)"/>
<let name="input/image" value="/sensing/camera/$(var namespace2)/image_raw"/>
<let name="input/camera_info" value="/sensing/camera/$(var namespace2)/camera_info"/>
<let name="output/rois2" value="/perception/traffic_light_recognition/$(var namespace2)/detection/rois"/>
<let name="output/traffic_signals2" value="/perception/traffic_light_recognition/$(var namespace2)/classification/traffic_signals"/>
<let name="output/car/traffic_signals2" value="/perception/traffic_light_recognition/$(var namespace2)/classification/car/traffic_signals"/>
<let name="output/pedestrian/traffic_signals2" value="/perception/traffic_light_recognition/$(var namespace2)/classification/pedestrian/traffic_signals"/>
<let name="map_based_detector_output_topic" value="rough/rois" if="$(var enable_fine_detection)"/>
<let name="map_based_detector_output_topic" value="rois" unless="$(var enable_fine_detection)"/>

<group unless="$(var fusion_only)">
<node pkg="topic_tools" exec="relay" name="traffic_light_camera_info_relay" args="$(var input/camera_info) camera_info"/>
<group>
<push-ros-namespace namespace="detection"/>
<include file="$(find-pkg-share autoware_traffic_light_map_based_detector)/launch/traffic_light_map_based_detector.launch.xml">
<arg name="input/camera_info" value="$(var input/camera_info)"/>
<arg name="expect/rois" value="expect/rois"/>
<arg name="output/rois" value="$(var map_based_detector_output_topic)"/>
<!-- This parameter should be configured differently for each camera considering their delay. -->
<arg name="min_timestamp_offset" value="-0.04"/>
<arg name="max_timestamp_offset" value="0.0"/>
</include>
</group>

<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light_node_container.launch.py">
<arg name="input/image" value="$(var input/image)"/>
<arg name="enable_image_decompressor" value="$(var enable_image_decompressor)"/>
<arg name="enable_fine_detection" value="$(var enable_fine_detection)"/>
<arg name="use_intra_process" value="true"/>
<arg name="use_multithread" value="true"/>
<arg name="fine_detector_param_path" value="$(var fine_detector_param_path)"/>
<arg name="car_classifier_param_path" value="$(var car_classifier_param_path)"/>
<arg name="pedestrian_classifier_param_path" value="$(var pedestrian_classifier_param_path)"/>
<arg name="output/rois" value="$(var output/rois2)"/>
<arg name="output/traffic_signals" value="$(var output/traffic_signals2)"/>
<arg name="output/car/traffic_signals" value="$(var output/car/traffic_signals2)"/>
<arg name="output/pedestrian/traffic_signals" value="$(var output/pedestrian/traffic_signals2)"/>
</include>
</group>

<group>
<push-ros-namespace namespace="classification"/>
<include file="$(find-pkg-share autoware_traffic_light_occlusion_predictor)/launch/traffic_light_occlusion_predictor.launch.xml">
<arg name="input/camera_info" value="$(var input/camera_info)"/>
<arg name="input/cloud" value="$(var input/cloud)"/>
<arg name="input/rois" value="$(var output/rois2)"/>
<arg name="input/car/traffic_signals" value="classified/car/traffic_signals"/>
<arg name="input/pedestrian/traffic_signals" value="classified/pedestrian/traffic_signals"/>
<arg name="output/traffic_signals" value="$(var output/traffic_signals2)"/>
</include>
</group>
<!-- traffic_light_occlusion_predictor on each camera -->
<group>
<include file="$(find-pkg-share tier4_perception_launch)/launch/traffic_light_recognition/traffic_light_occlusion_predictor.launch.py">
<arg name="all_camera_namespaces" value="$(var all_camera_namespaces)"/>
<arg name="input/cloud" value="$(var input/cloud)"/>
</include>
</group>

<!-- traffic_light_multi_camera_fusion -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2024 TIER IV, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import launch
from launch.actions import DeclareLaunchArgument
from launch.actions import GroupAction
from launch.actions import OpaqueFunction
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.actions import PushRosNamespace
import yaml


def create_traffic_light_camera_info_relay(namespace):
relay_node = Node(
package="topic_tools",
executable="relay",
name="traffic_light_camera_info_relay",
arguments=[f"/sensing/camera/{namespace}/camera_info", "camera_info"],
)

group = GroupAction(
[
PushRosNamespace(namespace),
relay_node,
]
)

return group


def launch_setup(context, *args, **kwargs):
# Load all camera namespaces
all_camera_namespaces = LaunchConfiguration("all_camera_namespaces").perform(context)

# Convert string to list
all_camera_namespaces = yaml.load(all_camera_namespaces, Loader=yaml.FullLoader)
if not isinstance(all_camera_namespaces, list):
raise ValueError(
"all_camera_namespaces is not a list. You should declare it like `['camera6', 'camera7']`."
)
if not all((isinstance(v, str) for v in all_camera_namespaces)):
raise ValueError(
"all_camera_namespaces is not a list of strings. You should declare it like `['camera6', 'camera7']`."
)

# Create containers for all cameras
traffic_light_recognition_containers = [
create_traffic_light_camera_info_relay(namespace) for namespace in all_camera_namespaces
]
return traffic_light_recognition_containers


def generate_launch_description():
return launch.LaunchDescription(
[
DeclareLaunchArgument("all_camera_namespaces", description="camera namespace list"),
OpaqueFunction(function=launch_setup),
]
)
Loading

0 comments on commit edb4179

Please sign in to comment.