• Stars
    star
    527
  • Rank 81,196 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated 7 months ago

Reviews

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

Repository Details

πŸ’¦ Seamless, distributed, real-time integration of Blender into PyTorch data pipelines

Build Status

blendtorch

blendtorch is a Python framework to seamlessly integrate Blender into PyTorch for deep learning from artificial visual data. We utilize Eevee, a new physically based real-time renderer, to synthesize images and annotations in real-time and thus avoid stalling model training in many cases.

If you find the project helpful, you consider citing it.

Feature summary

  • Data Generation: Stream distributed Blender renderings directly into PyTorch data pipelines in real-time for supervised learning and domain randomization applications. Supports arbitrary pickle-able objects to be send alongside images/videos. Built-in recording capability to replay data without Blender. Bi-directional communication channels allow Blender simulations to adapt during network training.
    More info [examples/datagen], [examples/compositor_normals_depth], [examples/densityopt]
  • OpenAI Gym Support: Create and run remotely controlled Blender gyms to train reinforcement agents. Blender serves as simulation, visualization, and interactive live manipulation environment.
    More info [examples/control]

The figure below visualizes the basic concept of blendtorch used in the context of generating artificial training data for a real-world detection task.


Fig 1: With Blendtorch, you are able to train your PyTorch modules on massively randomized artificial data generated by Blender simulations.

Getting started

  1. Read the installation instructions below
  2. To get started with blendtorch for training data training read [examples/datagen].
  3. To learn about using blendtorch for creating reinforcement training environments read [examples/control].

Prerequisites

This package has been tested with

  • Blender >= 2.83/2.91/3.0/3.1 (Python >= 3.7)
  • PyTorch >= 1.5/1.10 (Python >= 3.7)

running Windows 10 and Linux. Other versions might work as well, but have not been tested.

Installation

blendtorch is composed of two distinct sub-packages:

providing the PyTorch and Blender views on blendtorch. bendtorch.btt will be installed to your local Python environment, while blendtorch.btb will be installed to the Python environment that ships with Blender.

  1. Clone this repository

    git clone https://github.com/cheind/pytorch-blender.git <DST>
    
  2. Extend PATH

    Ensure Blender executable is in your environments lookup PATH. On Windows this can be accomplished by

    set PATH=c:\Program Files\Blender Foundation\Blender 2.91;%PATH%
    

    On Ubuntu when blender is installed using snap, the path may be included by adding the following line to your ~/.bashrc,

    export PATH=/snap/blender/current/${PATH:+:${PATH}}
    
  3. Complete Blender settings

    Open Blender at least once, and complete the initial settings. If this step is missed, some of the tests (especially the tests relating RL) will fail (Blender 2.91).

  4. Install blendtorch.btb

    Run

    blender --background --python <DST>/scripts/install_btb.py
    

    to blendtorch-btb into the Python environment bundled with Blender.

  5. Install blendtorch.btt

    Run

    pip install -e <DST>/pkg_pytorch
    

    installs blendtorch-btt into the Python environment that you intend to run PyTorch from.

  6. Install gym [optional]

    While not required, it is advised to install OpenAI gym if you intend to use blendtorch for reinforcement learning

    pip install gym
    
  7. Install dev requirements [optional]

    This step is optional. If you plan to run the unit tests

    pip install -r requirements_dev.txt
    pytest tests/
    

Troubleshooting

Run

blender --version

and check if the correct Blender version (>=2.83) is written to console. Next, ensure that blendtorch-btb installed correctly

blender --background --python-use-system-env --python-expr "import blendtorch.btb as btb; print(btb.__version__)"

which should print blendtorch version number on success. Next, ensure that blendtorch-btt installed correctly

python -c "import blendtorch.btt as btt; print(btt.__version__)"

which should print blendtorch version number on success.

Architecture

Please see [examples/datagen] and [examples/control] for an in-depth architectural discussion. Bi-directional communication is explained in [examples/densityopt].

Runtimes

The following tables show the mean runtimes per batch (8) and per image for a simple Cube scene (640x480xRGBA). See benchmarks/benchmark.py for details. The timings include rendering, transfer, decoding and batch collating. Reported timings are for Blender 2.8. Blender 2.9 performs equally well on this scene, but is usually faster for more complex renderings.

Blender Instances Runtime sec/batch Runtime sec/image Arguments
1 0.236 0.030 UI refresh
2 0.14 0.018 UI refresh
4 0.099 0.012 UI refresh
5 0.085 0.011 no UI refresh

Note: If no image transfer is needed, i.e in reinforcement learning of physical simulations, 2000Hz are easily achieved.

Cite

The code accompanies our academic work [1],[2] in the field of machine learning from artificial images. Please consider the following publications when citing blendtorch

@inproceedings{blendtorch_icpr2020_cheind,
    author = {Christoph Heindl, Lukas Brunner, Sebastian Zambal and Josef Scharinger},
    title = {BlendTorch: A Real-Time, Adaptive Domain Randomization Library},
    booktitle = {
        1st Workshop on Industrial Machine Learning 
        at International Conference on Pattern Recognition (ICPR2020)
    },
    year = {2020},
}

@inproceedings{robotpose_etfa2019_cheind,
    author={Christoph Heindl, Sebastian Zambal, Josef Scharinger},
    title={Learning to Predict Robot Keypoints Using Artificially Generated Images},
    booktitle={
        24th IEEE International Conference on 
        Emerging Technologies and Factory Automation (ETFA)
    },    
    year={2019}
}

Caveats

  • Despite offscreen rendering is supported in Blender 2.8x it requires a UI frontend and thus cannot run in --background mode. If your application does not require offscreen renderings you may enable background usage (see tests/ for examples).
  • The renderings produced by Blender are by default in linear color space and thus will appear darker than expected when displayed.

More Repositories

1

py-motmetrics

πŸ“Š Benchmark multiple object trackers (MOT) in Python
Python
1,331
star
2

dest

🐼 One Millisecond Deformable Shape Tracking Library (DEST)
C++
284
star
3

poisson-image-editing

Poisson image editing for seamless cloning and other operations
C++
244
star
4

py-thin-plate-spline

Code for computing interpolating / approximating thin plate splines.
Jupyter Notebook
156
star
5

inpaint

✏️ Inpaint is a C++ library providing image inpainting algorithms
C++
151
star
6

image-align

Variants of the classic Lucas-Kanade image alignment algorithm
C++
139
star
7

py-lapsolver

Fast linear assignment problem (LAP) solvers for Python based on c-extensions
Python
136
star
8

tf-matplotlib

Seamlessly integrate matplotlib figures as tensorflow summaries.
Python
119
star
9

mesh-deform

🍭 Physically plausible interactive 3D mesh deformation based on as rigid as possible constraints.
C++
73
star
10

pytorch-debayer

Convolutional PyTorch debayering / demosaicing layers
Python
56
star
11

autoregressive

πŸ₯ Autoregressive Models in PyTorch.
Python
56
star
12

pydantic-numpy

Seamlessly integrate numpy arrays into pydantic models.
Python
48
star
13

cppopt

Numerical optimization in C++
C++
38
star
14

parsley

Low-cost 3D scanner using Laser Triangulation
C#
35
star
15

sdftoolbox

Vectorized Python methods for creating, manipulating and tessellating signed distance fields.
Python
33
star
16

pure-torch-ngp

A pure PyTorch based implementation of "Instant Neural Graphics Primitives with a Multiresolution Hash Encoding" with tweaks.
Python
29
star
17

py-style-transfer

🎨 Artistic neural style transfer with tweaks in PyTorch
Jupyter Notebook
25
star
18

reconstructme-qt

ReconstructMe Qt UserInterface - Reference Implementation
C++
22
star
19

aam

Active Appearance Models in C++
C++
21
star
20

rgbd-correction

Code and data accompanying our work on spatio-thermal depth correction of RGB-D sensors based on Gaussian Process Regression in real-time.
Python
16
star
21

supershape

Python code to compute 3D parametric supershapes; additional Blender mesh generation support
Python
15
star
22

py-cgraph

🍊 Intro to symbolic computation in Python including applications to function optimization, physics simulation and more. Includes notebooks on back-propagation, auto-diff and more.
Python
14
star
23

py-minexr

Minimal, standalone, fast Python OpenEXR reader for single-part, uncompressed scan-line files as produced by Blender.
Python
12
star
24

rmds

Ruby Multidimensional Scaling Library
Ruby
12
star
25

py-control

PID controller playground in Python
Python
11
star
26

8point

8 Point algorithm for estimating fundamental matrix.
C++
11
star
27

python-hls-stream

Minimal HLS streaming demo with dynamic marker support in Python
Python
10
star
28

torch-spherical-harmonics

Real Spherical Harmonics for PyTorch
Python
10
star
29

py-globalflow

Python implementation of "Global Data Association for MOT Tracking using Network Flows"
Python
9
star
30

tikz-calibration-patterns

Latex, TikZ calibration pattern generation.
TeX
7
star
31

volplay

Manipulating, rendering and interacting with volumetric data
C++
6
star
32

gcsl

Implementation of "Learning to Reach Goals via Iterated Supervised Learning"
Python
5
star
33

pytorch-blender-dr

Jupyter Notebook
5
star
34

sympy-nondim

Non-dimensionalization of physical equations using sympy.
Python
5
star
35

py-probabilistic-robotics

Probabilistic robot localization
Python
4
star
36

gpu-bake

GPU vertex color baking
C++
4
star
37

py-mass-springs

Fast simulation of mass-spring systems
Python
4
star
38

py-microdots

A modern Python library to work with Anoto dot patterns.
Python
4
star
39

BilateralBlueNoisePointcloudSampling

C++
4
star
40

robot-pose

Estimate robot poses from 2d images
4
star
41

magic-texture

Generates psychedelic color textures in the spirit of Blender's magic texture shader using Python/Numpy
Python
4
star
42

py-rest-angularjs

Blueprint code for projects combining flask/aiohttp and AngularJS in a single web application
Python
3
star
43

motion-blend

Temporal blending of projectile motion estimates in 1D
Python
3
star
44

image-babble

ImageBabble is a lightweight C++ library to send and receive images
C++
3
star
45

py-classic-ai

Various classic artificial intelligence algorithms applied to common problems.
Python
3
star
46

py-dimensional-analysis

Dimensional analysis and modeling in Python
Python
3
star
47

bone-solve-ik

Fitting kinematic parameters to best align with set of noisy anchor points in Python.
Python
2
star
48

defocus

Structure from accidential motions for rendering synthetic apparature effects (focus change)
C++
2
star
49

qcv

Automatically exported from code.google.com/p/qcv
C#
2
star
50

jtypes

Bringing ECMAScript 5 types to C++
C++
2
star
51

py-gaussian-process

Gaussian processes samples
Python
2
star
52

monte-carlo-integration

Theory and implementation of Monte Carlo integration techniques
Python
2
star
53

cpp-restify

A framework for exposing RESTful APIs from C++
C++
2
star
54

score-matching

Jupyter Notebook
2
star
55

proximity-fusion

Code for "Enhanced Human-Machine Interaction by Combining Proximity Sensing with Global Perception" IROS 2019
Jupyter Notebook
2
star
56

kdmap

Automatically exported from code.google.com/p/kdmap
C#
1
star
57

py-videotime

Detect and extract time overlays in videos.
Python
1
star
58

pl-git-callback

A PyTorch-Lightning callback to increase model reproducibility through enforcing consistent git repository states upon training and validation.
Python
1
star
59

semi-supervised-em

Code for 'Notes on Semi-Supervised Expectation Maximization'
Jupyter Notebook
1
star
60

py-mcmc

Exemplary implementations of statistical methods for sampling from probability distributions
Jupyter Notebook
1
star
61

py-tonedetect

Capture tone sequences from real-time audio streams in Python
Jupyter Notebook
1
star
62

IoT-Scopes

Turns your Arduino into a software logic analyzer
C++
1
star
63

rpmk

Implementation of the 'Pyramide Match Kernel' in Ruby
Ruby
1
star
64

py-irdebug

Utilities for infrared signal debugging
C++
1
star
65

projective_circles

Experiments involving projective geometry of circles and how that affects computer vision tasks
Jupyter Notebook
1
star