I am using Blender for on-the-fly data generation for a machine learning task. The data creation process should be fast, and is conditioned on some parameter values given by my model, e.g., an RGB color value.
The model training happens in Python. For now, I pass the created values to Blender, where I have a script called render
, that reads the passed [args]
and uses them to render an image via bpy.ops.render.render
.
Python side:
os.system('blender -b testFile.blend --python-text render -- [args]')
Blender side:
# retrieve args
...
# set scene params with args
...
# render
bpy.context.scene.render.filepath = path
bpy.ops.render.render(write_still=True)
This works fine. The two main bottlenecks for speed are a) writing the image to (and reading it back from) disk, and b) opening and closing Blender every time. I can work around a) by setting up a RAM disk and writing/reading directly to/from that. But I don't know how to work around b).
Is it possible to always have Blender open in some background process, and then call its script render
which reads my arguments and renders an image?
os.system
from the terminal with an interactive python shell open? which OS are u using? $\endgroup$os.system
happens from within a python script, not an interactive shell. $\endgroup$