Coder Social home page Coder Social logo

mtlong / pytorch-blender Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cheind/pytorch-blender

0.0 1.0 0.0 28.21 MB

Seamless, distributed, real-time integration of Blender into PyTorch data pipelines

License: MIT License

Python 99.55% Batchfile 0.08% Shell 0.36%

pytorch-blender's Introduction

blendtorch

blendtorch is a Python framework to seamlessly integrate Blender renderings into PyTorch datasets 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.

Feature summary

  • Data Streaming: 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/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.

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

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{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}
}

@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},
}

Installation

blendtorch is composed of two distinct sub-packages: bendtorch.btt (in pkg_pytorch) and blendtorch.btb (in pkg_blender), providing the PyTorch and Blender views on blendtorch.

Prerequisites

This package has been tested with

  • Blender >= 2.83/2.90 (Python 3.7)
  • PyTorch >= 1.50 (Python 3.7/3.8) running Windows 10 and Linux.

Other versions might work as well, but have not been tested.

Clone this repository

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

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.83;%PATH%

Install blendtorch Blender part

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

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

Install blendtorch PyTorch part

pip install -e <DST>/pkg_pytorch

installs blendtorch-btt into the Python environment that you intend to run PyTorch from. While not required, it is advised to install OpenAI gym if you intend to use blendtorch for reinforcement learning

pip install gym

Developer instructions

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.

Caveats

  • Despite offscreen rendering is supported in Blender 2.8x it requires a UI frontend and thus cannot run in --background mode. You might be able to work around this issue using a fake screen as suggested by GNovich.
  • The renderings produced by Blender are by default in linear color space and thus will appear darker than expected when displayed.

pytorch-blender's People

Contributors

cheind avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.