Search Unity

Barracuda roadmap and continuing TensorFlow support?

Discussion in 'Barracuda' started by AndrewJones_, Apr 1, 2019.

  1. AndrewJones_

    AndrewJones_

    Joined:
    Nov 28, 2017
    Posts:
    3
    Hi all

    TL/DR first : Barracuda looks like an awesome step forwards and we love it when Unity NAILS cross-platform features. It looks ML-agents centric though, but we have a yearning for a more general inference engine for models developed in Keras / TensorFlow. Any intel on the Barracuda roadmap and model support in tensorflow_to_barracuda.py? Also we'd love to feed back specific model examples and other observations if there's an appetite for it under the heading of 'general inference' rather than 'ML agents'.

    We're currently working on some really interesting ML ideas for projects we're developing with Unity. As others have found, ml-agents is fairly narrowly focussed on its own subset of neural network architectures. We've had mixed results using tensorflow_to_barracuda.py on models built and trained externally with Keras / Tensorflow. Works a charm with a cleanly stripped model if we're very careful about what we use. Goes 'bang' (even on a frozen model) with things like dropouts, batch normalization (which tf2bc.py appears to try and handle) and LSTM. I appreciate that Unity might favour it's own 'spin' on ML / agents / inference engines, but IMO there's huge potential in servicing users who are coming from a "TensorFlow first" angle and just looking for a nice way of getting cross platform inference. Unity is so good at doing cross platform when it nails it that the thought of having to wrangle with TFLite, or the XLA TFCompiler, etc etc makes me sad ;-)

    I suspect that making Barracuda "100% TF compatible" is unlikely to happen, but are there any good approaches for making a 'Barracuda compliant' model in Keras? Examples of 'compliant LSTM' perhaps, tips for dropout or B.N. layers?

    I've had a dig around in ml-agents to see how tf2bc supports LSTM, and for examples of models constructed in, I assume, 'Barracuda compliant' fashion - e.g. tf.contrib.rnn.BasicLSTMCell being used in models.py, but info is fairly thin on the ground.

    Ta

    Andrew
     
    Psyco92, Octarina, Nanomid and 4 others like this.
  2. Nanomid

    Nanomid

    Joined:
    Nov 8, 2014
    Posts:
    15
    Have you continued to use ML-Agents/Inference Engine/Barracuda?
    And have you tried ONNX for your serialization format?

    TY
     
  3. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569
    Was there ever any official word back on this?

    Shame to see a relevant, well-written question get no response from anyone at Unity.
     
  4. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    378
    Andrew,

    Thanks for kind words. I am happy that people saw need and potential in cross-platform general inference engine. Indeed there is a significant interest from people to use Barracuda outside ML-agents.

    We took small steps, first keeping Barracuda as ML-agents centric. We needed time to explore different opportunities between TensorFlow, Keras and PyTorch and see how broad functionality of each framework maps to practical aspects of deploying to various platforms.

    Now, Barracuda is starting to take shape as a package of its own!
    https://github.com/Unity-Technologies/barracuda-release

    You can find documentation here: Documentation~/Barracuda.md. It could answer some of your questions. It briefly covers topics of installation, API and graph nodes that are supported already.

    We have chosen ONNX (Open Neural Network Exchange) standard as the primary file format to import pre-trained neural networks in Barracuda. Good news, you don't even need to run any python scripts - just drop .onnx file directly into your Unity project folder and it will import!


    What about TensorFlow (and TensorFlow2)? Right now we advise for conversion from TensorFlow to Barracuda is to use TF2ONNX converter.

    We will continue to support .pb files through tensorflow_to_barracuda.py script. However, even if slightly more expanded than just ML-Agents models, it is very limited support. As your said "100% TF compatible" is not going to happen any time soon. There are two issues. First, TensorFlow is not particularly keen on standardisation, API and internal representations are changing all the time. Second, TensorFlow internally uses very granular implementation of the - for instance LSTM actually consists of almost 100 smaller nodes. That is probably good, if you want to add new features to TensorFlow, but terribly inefficient for inference. There is plethora of tools that try to make sense of it - TFLite, XLA, TFCompiler and TF2ONNX. It is a hard problem however. We don't want to be stuck with something we never going to be able to do good. That is why we chose ONNX format for now.

    Why not Keras? Keras is awesome to boot, but we keep noticing that many practical Keras models end up using custom Lambda layers. And Lambda layer essentially forces model into full featured TensorFlow export. I expect Keras to become less dependent on Lambda layers in the future and we are going to re-evaluate Keras later in TensorFlow2 life cycle. For now, the same rules as with TensorFlow above applies - either try TF2ONNX converter or freeze the graph, export as .pb and use tensorflow_to_barracuda.py script.


    Currently Barracuda is on 0.x version and we still consider it as an early preview. That means you need to be adventurous to use Barracuda ;)

    We are now in position to take in specific model examples and get as much feedback from all of you guys as possible!
     
  5. ash_wind2

    ash_wind2

    Joined:
    Feb 20, 2019
    Posts:
    1
    Hi,

    Have tried to import sk-learn random forest model in unity barracuda package. But by default it is going into layer loop. So I have three questions regarding this -
    1. How to remove layer specification from barracuda package ?
    2. How to load sk-learn model in barracuda ?
    3. If Barracuda can not load model, then is there any other way to load random forest model in unity ?
     
  6. vincentgao88

    vincentgao88

    Unity Technologies

    Joined:
    Feb 7, 2018
    Posts:
    21
    Christin2015 and andybak like this.
  7. ReJ

    ReJ

    Unity Technologies

    Joined:
    Nov 1, 2008
    Posts:
    378
    Barracuda is intended only for Neural Networks.

    We have no plans to make Barracuda into general Machine Learning library. Just support for Neural Networks is huge undertaking on its own.

    In other words Barracuda will NOT support sk-learn nor algorithms like Random Forest any time soon, sorry.
     
    ROBYER1 and Christin2015 like this.
  8. WoWPerroDev

    WoWPerroDev

    Joined:
    Jan 26, 2019
    Posts:
    5
    Hello, I´m actually studing Game Programing, and for my thesis I´m trying to integrate a pre trained tensorflow model into unity, I first started using tensorflowsharp for my export, I froze a mnist test and could use it into unity, the thing was that I had to use tensorflow 1.5 instead of tensorflow 2.0, also people from the project in github told me it was probably not getting any updates soon. I actually prefer tensorflow 2.0 so I started reasearching a little bit more about how export a pretrained model with tensorflow 2.0 to Unity, I stumbled upon this post So i´m actually trying to use barracuda for the CNN deploy.

    would you reccommend going down this path?

    I just want to migrate a CNN that will diferenciate between drawings and paragraphs into unity, trained with tensorflow 2.0 in google collab with te NIST, Google QuickDraw, and other paragraph datasets. I haven´t used barracuda before, I actually wrote a question for this in stackoverflow and it got downvoted, so I´m asking for advice over here