TensorFlow

Hello devs!

For the past couple of months I’ve been working on bringing TensorFlow to UE4, enabling the use of state of the art machine learning in our projects. The plugin has reached something I think is ready to try out, but it is very much a work in progress so please check it out and give some feedback if you can!

Download
Plugin](Releases · getnamo/tensorflow-ue4 · GitHub)

https://img.shields.io/github/release/getnamo/tensorflow-ue4/all.svg

Examples Project](Releases · getnamo/tensorflow-ue4-examples · GitHub)

https://img.shields.io/github/release/getnamo/tensorflow-ue4-examples/all.svg

Plugin Variants
Embedded- GitHub - getnamo/tensorflow-ue4: TensorFlow plugin for Unreal Engine 4
Remote - GitHub - getnamo/machine-learning-remote-ue4: Machine Learning plugin for the Unreal Engine, encapsulating calls to remote python servers running e.g. Tensorflow/Pytorch.
Native - GitHub - getnamo/tensorflow-native-ue4: Tensorflow Plugin for Unreal Engine using C API for inference focus.

Limitations
Tensorflow-ue4 is Windows platform only. If you want to use a different platform for the client use the remote variant: GitHub - getnamo/machine-learning-remote-ue4: Machine Learning plugin for the Unreal Engine, encapsulating calls to remote python servers running e.g. Tensorflow/Pytorch.. Additional work is being done to widen backend support: Refactor to support Native and Remote variants · Issue #53 · getnamo/tensorflow-ue4 · GitHub

Resources
Latest documentation is always available at the github repositories.

Plugin

Examples Project

Examples - Mnist

Made a simple mnist recognition example.

Basic MNIST softmax classifier trained on begin play with sample training inputs streamed to the editor during training. When fully trained, UTexture2D (1-3) samples are tested for prediction.

you can even use your browser on your phone or desktop to draw some shapes to try recognition

Examples - Basic adding in TensorFlow
Want just the basics? check out the basic.umap map which uses addExample.py to add float array together. This is a good entry point to see how to pass UE4 blueprint data into and out of python tensorflow.

Examples - Upcoming Pong with QLearning AI

Still training the pong AI with sped up time dilation, but you can track updates in the qlearn branch of the examples repository.

Let me know what you think and what machine learning examples you’d like to see in the future!

3 Likes

@getnamo - This is awesome!

There are certain really cool projects that use TF that I’d love to be able to integrate into a game, e.g., Google’s NLP parser SyntaxNet.

Training a net to differentiate a person stepping vs just leaning in VR would also be really cool (though there’s a nice asset for doing this already on the marketplace VR Footstep Plugin), and allow people to use full body avatars in VR without having to have extra trackers other than hands and head.

Cool stuff
Would be awesome if we could use this to Train enemy AI in a RPG game /or enemies in RTS game and then save the progress

This is awesome!

You actually can

I am wondering if the new editor scripting capabilities can be used to directly integrate tensorflow into our projects?

It would be cool to see an LSTM for sequence learning in this! enemy predicting the players actions and acting on it.

Just curious: Can this plugin work after packaging?

Packaging support is a known missing feature. Progress is tracked here: Packaging Support · Issue #16 · getnamo/tensorflow-ue4 · GitHub, contributions welcome :slight_smile:

First of all, thank you very much @getnamo for your tremendous amount of work you’re giving away basically for free (the couple of bucks on the marketplace are merely symbolic in this regard). I’ve started to play with Reinforcement Learning and tensorflow using Unity and the Learning Agents preview they provide, but now have switched to Unreal because of - well, many reasons.

So already working with tensorflow, I was and still am excited that the Unreal environment also has integration already. Big thanks again for making this possible!

I also was used to having tensorboard for better understanding what is going on with my learning agent. I’ve tried for a day now to get tensorboard running (writing out logs with the simple MNIST example from Beginnen Sie mit TensorBoard  |  TensorFlow worked flawlessly), but I’m totally lost now, also because I’m just beginning writing python code, coming from a C++ and C# background. Have you tested running tensorboard already and could kindly give some guideline or tips how to make it work?

https://github.com/getnamo/tensorflo…SimpleBoard.py is the only experiment I did with tensorboard. My understanding is that you have to run tensorboard separately to host the webpage and then using something like the above, you can feed in all the data it needs for visualization. There isn’t anything in the plugin currently to bring that visualization into ue4, but you could use something like GitHub - ashea-code/BLUI: Rich HTML UI engine for UE4 or the inbuilt chromium to display the webpage inside ue4. If you get something working consider contributing a simple example to GitHub - getnamo/TensorFlow-Unreal-Examples: Drag and drop Unreal Engine TensorFlow examples repository.

Now that you say it, this absolutely makes sense. I tried to run tensorboard from inside UE, the idea that I easily could run it from a standalone python console as well on the logs didn’t come to my mind at that time. Thanks for the enlightenment.

I’ll experiment with the inbuilt chromium browser first. I wanted to adopt the workflow and setup Unity uses (external python distro via Anaconda) anyways since they have some nice goodies in their SDK like curiosity reinforced learning, circulum learning, imitation learning etc, and I’ll certainly contribute it to your repo as soon as it’s stable.
Do you prefer pull requests from a branch, a fork or another way?

Sounds good :). A pull request on master is fine, I can always retarget it to a working branch if it breaks too much

Recent update:
With the v0.10.1 (Release v0.10.1 for UE4.20 · getnamo/tensorflow-ue4 · GitHub) release the plugin now supports packaging. Let me know if there are any issues with this.

Have you released the pong game yet? I’m currently developing a simple 2d game with a stick that tries to avoid enemies that are moving in the environment by pulling up/down the stick.

This is incredibly cool coding ! Can one use ue4 node editor as general c++ visual coding platform, by following this gourgeous implementation ? Is it basically about linking dll functions to the blueprint nodes ?

The unreal side for communicating data is typically done in blueprint (node editor) via a *TensorflowComponent *and the machine learning is done in python (which is what tensorflow uses so you can copy paste examples).

Implemented it in a separate branch of the example project: GitHub - getnamo/TensorFlow-Unreal-Examples at qlearn. All the pieces are there, it’s just missing a trained network to work in theory.

This is awesome!

Is tensorflow 2.0 supported and would I need to change something to get it download by pip?

In theory just changing “tensorflow”: “1.10.0”, to *“2.0.0” *inside TensorFlow-Unreal/Content/Scripts/upymodule.json at master · getnamo/TensorFlow-Unreal · GitHub should do what you’re looking for, but there may be gremlins in the new tf API, kindly open a github issue with details (Issues · getnamo/TensorFlow-Unreal · GitHub) if you run into problems.