• Stars
    star
    2,083
  • Rank 21,381 (Top 0.5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 4 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A procedural Blender pipeline for photorealistic training image generation

BlenderProc2

Documentation Open In Collab License: GPL v3

Front readme image

A procedural Blender pipeline for photorealistic rendering.

Documentation | Tutorials | Examples | ArXiv paper | Workshop paper | JOSS article

Features

  • Loading: *.obj, *.ply, *.blend, *.fbx, BOP, ShapeNet, Haven, 3D-FRONT, etc.
  • Objects: Set or sample object poses, apply physics and collision checking.
  • Materials: Set or sample physically-based materials and textures
  • Lighting: Set or sample lights, automatic lighting of 3D-FRONT scenes.
  • Cameras: Set, sample or load camera poses from file.
  • Rendering: RGB, stereo, depth, normal and segmentation images/sequences.
  • Writing: .hdf5 containers, COCO & BOP annotations.

Installation

Via pip

The simplest way to install blenderproc is via pip:

pip install blenderproc

Via git

Alternatively, if you need to make changes to blenderproc or you want to make use of the most recent version on the main-branch, clone the repository:

git clone https://github.com/DLR-RM/BlenderProc

To still make use of the blenderproc command and therefore use blenderproc anywhere on your system, make a local pip installation:

cd BlenderProc
pip install -e .

Usage

BlenderProc has to be run inside the blender python environment, as only there we can access the blender API. Therefore, instead of running your script with the usual python interpreter, the command line interface of BlenderProc has to be used.

blenderproc run <your_python_script>

In general, one run of your script first loads or constructs a 3D scene, then sets some camera poses inside this scene and renders different types of images (RGB, distance, semantic segmentation, etc.) for each of those camera poses. Usually, you will run your script multiple times, each time producing a new scene and rendering e.g. 5-20 images from it. With a little more experience, it is also possible to change scenes during a single script call, read here how this is done.

Quickstart

You can test your BlenderProc pip installation by running

blenderproc quickstart

This is an alias to blenderproc run quickstart.py where quickstart.py is:

import blenderproc as bproc
import numpy as np

bproc.init()

# Create a simple object:
obj = bproc.object.create_primitive("MONKEY")

# Create a point light next to it
light = bproc.types.Light()
light.set_location([2, -2, 0])
light.set_energy(300)

# Set the camera to be in front of the object
cam_pose = bproc.math.build_transformation_mat([0, -5, 0], [np.pi / 2, 0, 0])
bproc.camera.add_camera_pose(cam_pose)

# Render the scene
data = bproc.renderer.render()

# Write the rendering into an hdf5 file
bproc.writer.write_hdf5("output/", data)

BlenderProc creates the specified scene and renders the image into output/0.hdf5. To visualize that image, simply call:

blenderproc vis hdf5 output/0.hdf5

Thats it! You rendered your first image with BlenderProc!

Debugging in the Blender GUI

To understand what is actually going on, BlenderProc has the great feature of visualizing everything inside the blender UI. To do so, simply call your script with the debug instead of run subcommand:

blenderproc debug quickstart.py

Make sure that quickstart.py actually exists in your working directory.

Now the Blender UI opens up, the scripting tab is selected and the correct script is loaded. To start the BlenderProc pipeline, one now just has to press Run BlenderProc (see red circle in image). As in the normal mode, print statements are still printed to the terminal.

Front readme image

The pipeline can be run multiple times, as in the beginning of each run the scene is cleared.

Breakpoint-Debugging in IDEs

As blenderproc runs in blenders separate python environment, debugging your blenderproc script cannot be done in the same way as with any other python script. Therefore, remote debugging is necessary, which is explained for vscode and PyCharm in the following:

Debugging with vscode

First, install the debugpy package in blenders python environment.

blenderproc pip install debugpy

Now add the following configuration to your vscode launch.json.

{                        
    "name": "Attach",
    "type": "python",
    "request": "attach",
    "connect": {
        "host": "localhost",
        "port": 5678
    }
}

Finally, add the following lines to the top (after the imports) of your blenderproc script which you want to debug.

import debugpy
debugpy.listen(5678)
debugpy.wait_for_client()

Now run your blenderproc script as usual via the CLI and then start the added "Attach" configuration in vscode. You are now able to add breakpoints and go through the execution step by step.

Debugging with PyCharm Professional

In Pycharm, go to Edit configurations... and create a new configuration based on Python Debug Server. The configuration will show you, specifically for your version, which pip package to install and which code to add into the script. The following assumes Pycharm 2021.3:

First, install the pydevd-pycharm package in blenders python environment.

blenderproc pip install pydevd-pycharm~=212.5457.59

Now, add the following code to the top (after the imports) of your blenderproc script which you want to debug.

import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=12345, stdoutToServer=True, stderrToServer=True)

Then, first run your Python Debug Server configuration in PyCharm and then run your blenderproc script as usual via the CLI. PyCharm should then go in debug mode, blocking the next code line. You are now able to add breakpoints and go through the execution step by step.

What to do next?

As you now ran your first BlenderProc script, your ready to learn the basics:

Tutorials

Read through the tutorials, to get to know with the basic principles of how BlenderProc is used:

  1. Loading and manipulating objects
  2. Configuring the camera
  3. Rendering the scene
  4. Writing the results to file
  5. How key frames work
  6. Positioning objects via the physics simulator

Examples

We provide a lot of examples which explain all features in detail and should help you understand how BlenderProc works. Exploring our examples is the best way to learn about what you can do with BlenderProc. We also provide support for some datasets.

and much more, see our examples for more details.

Contributions

Found a bug? help us by reporting it. Want a new feature in the next BlenderProc release? Create an issue. Made something useful or fixed a bug? Start a PR. Check the contributions guidelines.

Change log

See our change log.

Citation

If you use BlenderProc in a research project, please cite as follows:

@article{Denninger2023, 
    doi = {10.21105/joss.04901},
    url = {https://doi.org/10.21105/joss.04901},
    year = {2023},
    publisher = {The Open Journal}, 
    volume = {8},
    number = {82},
    pages = {4901}, 
    author = {Maximilian Denninger and Dominik Winkelbauer and Martin Sundermeyer and Wout Boerdijk and Markus Knauer and Klaus H. Strobl and Matthias Humt and Rudolph Triebel},
    title = {BlenderProc2: A Procedural Pipeline for Photorealistic Rendering}, 
    journal = {Journal of Open Source Software}
} 

More Repositories

1

stable-baselines3

PyTorch version of Stable Baselines, reliable implementations of reinforcement learning algorithms.
Python
7,958
star
2

rl-baselines3-zoo

A training framework for Stable Baselines3 reinforcement learning agents, with hyperparameter optimization and pre-trained agents included.
Python
1,796
star
3

3DObjectTracking

Algorithms and Publications on 3D Object Tracking
C++
592
star
4

AugmentedAutoencoder

Official Code: Implicit 3D Orientation Learning for 6D Object Detection from RGB Images
Python
318
star
5

SingleViewReconstruction

Official Code: 3D Scene Reconstruction from a Single Viewport
Python
258
star
6

RAFCON

RAFCON (RMC advanced flow control) uses hierarchical state machines, featuring concurrent state execution, to represent robot programs. It ships with a graphical user interface supporting the creation of state machines and contains IDE like debugging mechanisms. Alternatively, state machines can programmatically be generated using RAFCON's API.
Python
179
star
7

rl-trained-agents

A collection of pre-trained RL agents using Stable Baselines3
Python
92
star
8

granite

C++
49
star
9

oaisys

Python
48
star
10

instr

code of paper โ€žUnknown Object Segmentation from Stereo Imagesโ€œ, IROS 2021
Python
41
star
11

curvature

Official Code: Estimating Model Uncertainty of Neural Networks in Sparse Information Form, ICML2020.
Python
23
star
12

amp

Point-to-point motion planning library for articulated robots.
C++
13
star
13

DistinctNet

"What's This?" - Learning to Segment Unknown Objects from Manipulation Sequences
Python
11
star
14

rosmc

ROS Mission Control (ROSMC) -- A high-level mission designining and monitoring tool with intuitive graphical interfaces
Python
9
star
15

moegplib

Official Code: Trust Your Robots! Predictive Uncertainty Estimation of Neural Networks with Sparse Gaussian Processes
Python
8
star
16

ExReNet

Learning to Localize in New Environments from Synthetic Training Data
Python
7
star
17

python-jsonconversion

Convert arbitrary Python objects into JSON strings and back.
Python
6
star
18

GRACE

Graph Assembly processing networks for robotic assembly sequence planning and feasibility learning
Python
6
star
19

RAFCON-ros-state-machines

RAFCON state machine examples using the ROS middleware
Python
5
star
20

python-yaml-configuration

Python
4
star
21

BayesSim2Real

Source code for IROS 2022 paper: Bayesian Active Learning for Sim-to-Real Robotic Perception.
Python
4
star
22

TendonDrivenContinuum

4
star
23

multicam_dataset_reader

C++
2
star
24

stios-utils

utility functions for the [Stereo Instance on Surfaces (STOIS) dataset
Python
2
star
25

SemanticSingleViewReconstruction

C++
1
star
26

rafcon-task-planner-plugin

A Plugin for RAFCON to interface arbitrary PDDL Planner.
Python
1
star
27

RECALL

Code and image database for IROS2022 paper "RECALL: Rehearsal-free Continual Learning for Object Classification". A algorithm to learn new object categories on the fly without forgetting the old ones and without the need to save previous images.
Python
1
star