DeepSonar is a Blender-based simulation toolkit for generating forward-looking sonar imagery from 3D assets (.glb) along with paired RGB views and pose files.
The repository contains multiple script variants, including baseline CPU implementations and optional NVIDIA Warp-accelerated pipelines.
- Forward-looking sonar ray-casting in Blender scenes
- Polar and fan-shaped cartesian sonar image generation
- Optional speckle and backscatter noise modeling
- Object-aware sonar crop export
- Paired RGB image rendering from matching viewpoints
- Sonar/camera pose export as
.npy - Optional GPU acceleration for histogram/binning (Warp)
DeepSonar/
README.md
Sonar/
scan.py # Full spherical scan pipeline (GLB import, sonar + RGB + poses)
SonarIllumination.py # Baseline single-scene sonar projection + noise + cartesian export
warp_sonar.py # Warp-optional acceleration example (CLI Blender script)
warp_final.py # Warp-optional module with public API run_sonar_pipeline(...)
- Blender (tested with Python 3.11 runtime embedded in Blender)
- Python packages available to Blender's Python:
numpytorchmatplotlibscipyPillow
- NVIDIA GPU + CUDA driver
warp-langPython package (imported aswarp)
If Warp is unavailable, scripts automatically fall back to CPU paths where implemented.
Because these scripts run inside Blender, install packages into Blender's Python environment (or an environment Blender can access).
Example (replace Blender Python path as needed):
"/path/to/blender/3.x/python/bin/python3.11" -m pip install numpy torch matplotlib scipy pillow warp-langIf you run Blender with your system/site packages enabled, ensure those packages are also visible from Blender runtime.
This is the most comprehensive script in the repo. It:
- Imports and normalizes a
.glb - Samples viewpoints over a spherical grid
- Generates:
sonar_polar/*.pngsonar_cartesian/*.pngcropped_sonar_cartesian/*.png(when object hits are detected)rgb/*.pngposes/*_sonar_pose.npy
Run from Blender:
blender -b -P Sonar/scan.pyImportant: scan.py currently contains hardcoded paths in the main(...) call near the end of the file.
Edit those to your local GLB input path and output directory before running.
This script performs sonar projection for the current Blender scene, applies noise, and saves a cartesian sonar image to:
//renders/fan_with_ticks.png(Blender-relative path)
Run:
blender -b your_scene.blend -P Sonar/SonarIllumination.pyCLI-style script that keeps sonar math similar to baseline while accelerating accumulation with Warp when available.
Run:
blender -b your_scene.blend -P Sonar/warp_sonar.pyExposes:
run_sonar_pipeline(output_path="//renders/fan_with_ticks.png")Can be run directly:
blender -b your_scene.blend -P Sonar/warp_final.pyDepending on script and mode, output directories typically include:
rgb/: RGB renders at sonar viewpointssonar_polar/: polar-projected sonar imagessonar_cartesian/: fan/cartesian sonar imagescropped_sonar_cartesian/: tight sonar crops around object-hit regionsposes/: sonar pose matrices (.npy)
Each script has editable constants near the top:
LIGHT_ORIGIN,TARGET_CENTERcam_info:azi_range,azi_binsrad_range,rad_binsele_range,pp_arc
- Noise settings (variance, backscatter scale/mode)
- Spherical scan sampling (
azim_step_deg,elev_step_deg, radius)
For scan.py, also update:
- Input GLB path in
main(...) - Base output path in
main(...)
- Several scripts are designed for Blender scripting context and may not run correctly with plain
python script.py. - Some paths are absolute/hardcoded by default; update them for portability.
- Higher ray counts (
azi_bins * pp_arc) can be computationally expensive. - Warp acceleration only applies to supported sections and only when CUDA + Warp are detected.
-
ModuleNotFoundErrorinside Blender
Install dependencies into Blender's Python environment. -
No output image appears
Check output paths (bpy.path.abspath(...)) and write permissions. -
Very slow execution
Reduceazi_bins,pp_arc, or viewpoint count; use Warp-enabled scripts when possible. -
Black/empty sonar image
Verify scene/object placement, sonar origin/target, andrad_rangecoverage.