ROS Package bob_sd35
A ROS2 package for image generation using Stable Diffusion 3.5 Large.
This package provides two nodes:
itti - Image & Text to Image generation (img2img)
tti - Text to Image generation (text2img)
Both nodes automatically download the SD3.5 model from HuggingFace on first run and support CPU offloading for systems with limited VRAM.
Note: The SD3.5 Large model is approximately 67 GB in size. The initial download will take a significant amount of time depending on your internet connection.
Dependencies
System Dependencies
ROS2 Humble
ros-humble-cv-bridge
ros-humble-image-transport
Python Dependencies
Install via pip:
pip install -r requirements.txt
Installation and Building
Note: It is recommended to use a Python virtual environment for installing the Python dependencies to avoid conflicts with system packages.
# Clone the repository
cd ~/ros2_ws/src
git clone https://github.com/bob-ros2/bob_sd35.git
# Install Python dependencies (preferably in a virtual environment)
pip install -r bob_sd35/requirements.txt
# Build the package
cd ~/ros2_ws
colcon build --packages-select bob_sd35
# Source the workspace
source install/setup.bash
Nodes
This package provides two nodes for different use cases:
Node |
Description |
|---|---|
|
Image & Text to Image - Transforms an input image based on a text prompt using img2img pipeline. Requires |
|
Text to Image - Generates images purely from text prompts using text2img pipeline. No input image required. |
Usage
ITTI Node (Image-to-Image)
One-shot generation:
ros2 run bob_sd35 itti --ros-args \
-p model_path:=/path/to/models/stable-diffusion-3.5-large \
-p input_prompt:="a beautiful sunset" \
-p input_image:=/path/to/input.jpg \
-p output_image:=auto \
-p once:=true
Continuous mode (topic-based):
ros2 run bob_sd35 itti --ros-args \
-p model_path:=/path/to/models/stable-diffusion-3.5-large \
-p input_image:=/path/to/default_input.jpg \
-p output_image:=auto
Then publish prompts:
# Plain text prompt (uses input_image parameter)
ros2 topic pub --once --keep-alive 1.0 /input_prompt std_msgs/msg/String "data: 'forest background'"
# JSON with image_url (ITTI only - overrides input_image parameter)
ros2 topic pub --once --keep-alive 1.0 /input_prompt std_msgs/msg/String \
"data: '{\"role\": \"user\", \"content\": \"cosmic background\", \"image_url\": \"file:///path/to/image.jpg\"}'"
TTI Node (Text-to-Image)
One-shot generation:
ros2 run bob_sd35 tti --ros-args \
-p model_path:=/path/to/models/stable-diffusion-3.5-large \
-p input_prompt:="a spacecraft in deep space" \
-p output_image:=spacecraft.png \
-p once:=true
Continuous mode (topic-based):
ros2 run bob_sd35 tti --ros-args \
-p model_path:=/path/to/models/stable-diffusion-3.5-large \
-p output_image:=auto
Then publish prompts:
ros2 topic pub --once --keep-alive 1.0 /input_prompt std_msgs/msg/String "data: 'a beautiful mountain landscape'"
Subscribed Topics
Topic |
Type |
Description |
|---|---|---|
|
|
Text prompt to trigger image generation. For itti: accepts plain text or JSON with |
Published Topics
Topic |
Type |
Description |
|---|---|---|
|
|
Generated image published when subscribers are connected. |
ROS Parameters
Both nodes share most parameters. Parameters marked with (itti only) are only available in the itti node.
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
string |
|
HuggingFace model repository ID. |
|
string |
|
Path to the local model directory. |
|
string |
|
Initial prompt for generation. |
|
string |
|
(itti only) Initial input image path. |
|
string |
|
Output image path. If ending with |
|
double |
|
(itti only) Denoising strength (0.0-1.0). Low=keep original, high=more change. |
|
double |
|
Classifier-free guidance scale. |
|
string |
|
Negative prompt to exclude unwanted elements from generation. |
|
int |
|
Number of inference steps. |
|
bool |
|
If true, shuts down after first generation. |
|
bool |
|
Enable model CPU offload to save VRAM. |
|
bool |
|
Keep model loaded between generations. Set to true to save loading time. |
|
double |
|
Seconds to wait before shutdown when |
|
int |
|
Random seed for reproducibility. Use -1 for random seed each generation. |
Environment Variables
All parameters can also be set via environment variables with prefix ITTI_ for the itti node and TTI_ for the tti node (e.g., ITTI_MODEL_PATH, TTI_GUIDANCE_SCALE).