Skip to content
Merged
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
13 changes: 13 additions & 0 deletions depth_anything_3_ros2/da3_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ def is_service_available(self) -> bool:
"""Check if host TRT service is currently available."""
return self._check_service()

def get_gpu_memory_usage(self) -> Optional[Dict[str, float]]:
"""
Get GPU memory usage (not available for shared memory inference).

Returns:
None - GPU memory is managed by host TRT service
"""
return None

def clear_cache(self) -> None:
"""Clear cache (no-op for shared memory inference)."""
pass


class DA3InferenceWrapper:
"""
Expand Down
38 changes: 28 additions & 10 deletions depth_anything_3_ros2/depth_anything_3_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from std_msgs.msg import Header
from cv_bridge import CvBridge, CvBridgeError

from .da3_inference import DA3InferenceWrapper
from .da3_inference import DA3InferenceWrapper, SharedMemoryInference
from .utils import normalize_depth, colorize_depth, PerformanceMetrics


Expand Down Expand Up @@ -44,17 +44,29 @@ def __init__(self):
# Initialize performance metrics
self.metrics = PerformanceMetrics(window_size=30)

# Initialize DA3 model
self.get_logger().info(
f"Initializing Depth Anything 3 with model: {self.model_name}"
)
# Initialize inference backend
try:
self.model = DA3InferenceWrapper(
model_name=self.model_name, device=self.device, cache_dir=self.cache_dir
)
self.get_logger().info("Model loaded successfully")
if self.use_shared_memory:
self.get_logger().info(
"Initializing SharedMemoryInference for host TRT communication"
)
self.model = SharedMemoryInference(timeout=1.0)
if self.model.is_service_available:
self.get_logger().info("Host TRT service detected and ready")
else:
self.get_logger().warn(
"Host TRT service not detected - will retry on first inference"
)
else:
self.get_logger().info(
f"Initializing Depth Anything 3 with model: {self.model_name}"
)
self.model = DA3InferenceWrapper(
model_name=self.model_name, device=self.device, cache_dir=self.cache_dir
)
self.get_logger().info("Inference backend initialized successfully")
except Exception as e:
self.get_logger().error(f"Failed to load model: {e}")
self.get_logger().error(f"Failed to initialize inference backend: {e}")
raise

# Setup QoS profile for subscriptions
Expand Down Expand Up @@ -122,6 +134,9 @@ def _declare_parameters(self) -> None:
# Logging
self.declare_parameter("log_inference_time", False)

# Jetson TRT mode (host-container split)
self.declare_parameter("use_shared_memory", False)

def _load_parameters(self) -> None:
"""Load parameters from ROS2 parameter server."""
# Model configuration
Expand All @@ -148,6 +163,9 @@ def _load_parameters(self) -> None:
# Logging
self.log_inference_time = self.get_parameter("log_inference_time").value

# Jetson TRT mode
self.use_shared_memory = self.get_parameter("use_shared_memory").value

def camera_info_callback(self, msg: CameraInfo) -> None:
"""
Store latest camera info for republishing with depth images.
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
- ./models:/root/.cache/huggingface:rw
- ./examples:/examples:ro
- ./config:/app/config:ro
command: bash
command: bash -c "source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && exec bash"

# GPU-enabled deployment (requires nvidia-docker)
depth-anything-3-gpu:
Expand Down Expand Up @@ -57,7 +57,7 @@ services:
- ./config:/app/config:ro
- /dev:/dev:rw # For camera access
privileged: true # Required for camera access
command: bash
command: bash -c "source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && exec bash"

# Jetson ARM64 deployment (for NVIDIA Jetson devices)
# Requires JetPack 6.2+ (L4T R36.4.x) with TensorRT 10.3 on host
Expand Down Expand Up @@ -106,7 +106,7 @@ services:
- /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so.10.3.0:/usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so.10:ro
- /usr/lib/aarch64-linux-gnu/libnvonnxparser.so.10.3.0:/usr/lib/aarch64-linux-gnu/libnvonnxparser.so.10:ro
privileged: true
command: bash
command: bash -c "source /opt/ros/humble/install/setup.bash 2>/dev/null || source /opt/ros/humble/setup.bash && source /ros2_ws/install/setup.bash && exec bash"

# Development environment with mounted source
depth-anything-3-dev:
Expand Down
8 changes: 8 additions & 0 deletions launch/depth_anything_3.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def generate_launch_description():
description='Log per-frame inference time and performance metrics'
),

# Jetson TRT mode (host-container split)
DeclareLaunchArgument(
'use_shared_memory',
default_value='false',
description='Use shared memory for host TRT service communication (Jetson only)'
),

# Node
Node(
package='depth_anything_3_ros2',
Expand All @@ -136,6 +143,7 @@ def generate_launch_description():
'queue_size': LaunchConfiguration('queue_size'),
'processing_threads': LaunchConfiguration('processing_threads'),
'log_inference_time': LaunchConfiguration('log_inference_time'),
'use_shared_memory': LaunchConfiguration('use_shared_memory'),
}]
),
])
Loading