Skip to content

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 ​

python
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 ​

python
images_written = generator.generate(num_images=6)
ParameterDefaultDescription
num_imagesNoneNumber of images (camera views) to write. The last scene's views are trimmed to hit the count exactly.
num_samplesNoneNumber of scenes instead. Every camera view of every scene is written. Keyword only.
clean_up_environmentTrueRelease the engine and environment when done, even on error. Workers set it to False to reuse the environment across shards.
save_blender_sceneFalseAlso 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:

python
engine = BlenderEngine(
    config.RenderConfig(device="METAL", samples=64),
    config.PhysicsConfig(active=True),
)

RenderConfig ​

FieldDefaultDescription
device"CUDA"CUDA, OPTIX, HIP, METAL or CPU
samplesNoneCycles samples per pixel. None keeps the renderer default. Lower is faster and noisier
noise_thresholdNoneAdaptive sampling threshold, > 0
max_retries2Retries for a failed render
verboseFalseRenderer logging
depth, normalsFalseRender 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.

FieldDefaultDescription
activeFalseRun 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_interval2.0Seconds between checks whether everything has stopped
model_stopped_location_threshold0.01Movement below which a model counts as stopped (m)
model_stopped_rotation_threshold0.1Rotation below which a model counts as stopped
substeps_per_frame, solver_iters10, 10Solver accuracy
use_volume_comFalseUse the volume center of mass
verboseFalseSimulation logging

Writers ​

CocoWriter is the writer for instance-segmentation datasets:

python
writer = CocoWriter(output_dir="output/my_dataset", include_camera_metadata=True)
ParameterDefaultDescription
output_dirNoneTarget directory. None creates output/synthetic_data_<date>_<id>/
color_file_format"JPEG"JPEG or PNG
jpg_quality90JPEG quality, 0–100
include_camera_metadataFalseStore each image's camera pose (camera_matrix_world) and lens (camera_lens_mm) in the image record
info, licensesNoneCOCO info and licenses blocks
supercategory_mapNoneCategory 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:

python
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.

Randomizer Nodes
The building blocks of variation: instances, poses, materials, backgrounds, lights and cameras.
Explore the nodes →