SyntheticDataGenerator
SUMMARY
SyntheticDataGenerator runs the loop that produces a dataset: for each sample it randomizes a scene, optionally simulates physics, renders the camera views and writes images and annotations. It ties together an Environment, a Randomizer, a writer and a BlenderEngine.
Construction
from telekinesis.illusion import config
from telekinesis.illusion.core.engine import BlenderEngine
from telekinesis.illusion.core.synthetic_data_generator import SyntheticDataGenerator
from telekinesis.illusion.writer.writer import CocoWriter
generator = SyntheticDataGenerator(
environment=environment,
randomizer=randomizer,
writer=CocoWriter(output_dir="output/my_dataset"),
engine=BlenderEngine(config.RenderConfig(device="CPU", samples=16)),
)environment, randomizer and writer are required. Without engine, the generator uses BlenderEngine(): CUDA rendering with physics off.
Generate
images_written = generator.generate(num_images=6)| Parameter | Default | Description |
|---|---|---|
num_images | None | Number of images (camera views) to write. The last scene's views are trimmed to hit the count exactly. |
num_samples | None | Number of scenes instead. Every camera view of every scene is written. Keyword only. |
clean_up_environment | True | Release the engine and environment when done, even on error. Workers set it to False to reuse the environment across shards. |
save_blender_scene | False | Also save the last scene as scene_<uuid>.blend in the output directory, to inspect it in Blender. |
Pass num_images or num_samples, not both; with neither, 5 images are written. The return value is the number of images written. Each sample renders number_of_views images, one per pose drawn by the CameraPoseRandomizer, so num_images=6 with two views per sample renders three scenes.
Engine
BlenderEngine(render_config=None, physics_config=None) renders with Cycles through the bundled bpy. Both settings are configs:
engine = BlenderEngine(
config.RenderConfig(device="METAL", samples=64),
config.PhysicsConfig(active=True),
)RenderConfig
| Field | Default | Description |
|---|---|---|
device | "CUDA" | CUDA, OPTIX, HIP, METAL or CPU |
samples | None | Cycles samples per pixel. None keeps the renderer default. Lower is faster and noisier |
noise_threshold | None | Adaptive sampling threshold, > 0 |
max_retries | 2 | Retries for a failed render |
verbose | False | Renderer logging |
depth, normals | False | Render depth and normal passes. CocoWriter does not save them |
PhysicsConfig
With active=True, every scene is simulated after the randomizer places the models: models with active_in_simulation=True fall and settle on the static ones (a bin, a table) before the views are rendered. Models that fall below every static model, such as parts that miss the bin, are hidden automatically and are neither rendered nor annotated.
| Field | Default | Description |
|---|---|---|
active | False | Run the simulation |
min_simulation_time_range | (0.5, 1.0) | Seconds always simulated, drawn per scene |
max_simulation_time_range | (2.0, 5.0) | Upper bound on simulated seconds, drawn per scene |
check_model_interval | 2.0 | Seconds between checks whether everything has stopped |
model_stopped_location_threshold | 0.01 | Movement below which a model counts as stopped (m) |
model_stopped_rotation_threshold | 0.1 | Rotation below which a model counts as stopped |
substeps_per_frame, solver_iters | 10, 10 | Solver accuracy |
use_volume_com | False | Use the volume center of mass |
verbose | False | Simulation logging |
Writers
CocoWriter is the writer for instance-segmentation datasets:
writer = CocoWriter(output_dir="output/my_dataset", include_camera_metadata=True)| Parameter | Default | Description |
|---|---|---|
output_dir | None | Target directory. None creates output/synthetic_data_<date>_<id>/ |
color_file_format | "JPEG" | JPEG or PNG |
jpg_quality | 90 | JPEG quality, 0–100 |
include_camera_metadata | False | Store each image's camera pose (camera_matrix_world) and lens (camera_lens_mm) in the image record |
info, licenses | None | COCO info and licenses blocks |
supercategory_map | None | Category ID → COCO supercategory. Unmapped categories get "coco_annotations" |
It writes images/000000.jpg, ... and one coco_annotations.json. Every visible, annotated instance gets a compressed-RLE mask, a bounding box [x, y, w, h] and its area. writer.get_output_dir() returns the directory. Writing to an existing directory appends, continuing the image numbering.
To write another format, subclass telekinesis.illusion.writer.writer.Writer and implement write(result) -> int, which receives the rendered frames as a RenderResult.
Lifecycle
generate() calls prepare() before the first sample. Call prepare() yourself when you need the imported models before generation, for example to move a static container:
generator.prepare()
environment.get_models_by_name("plastic_bin_2").set_location((0.0, 0.0, -0.05))
generator.generate(num_images=20)clean_up() releases the engine and the environment; with clean_up_environment=True, generate() calls it for you.