Unity ML-Agents Tutorial | AI Truffle Pigs! šŸ·

This tutorial is a bit staleā€¦ for a new tutorial built with the latest version of ML-Agents, check this out:

penguinmla_thumb.jpg

Unity ML Agents | Penguins

In this Unity ML Agents tutorial youā€™ll learn how to use machine learning, specifically reinforcement learning in Unity to train penguins to find fish and feed their babies.


If you still want to do the pig tutorial, thereā€™s still value to be gained, but there are a few changes to ML-Agents that will require changing. Iā€™ve noted them below.

šŸ‘‡ Video updates further down the page!

Intro

Learn how to create AI truffle-seeking pigs with Unity ML-Agents and Tensorflow!

This page is a companion to the YouTube tutorial above on creating intelligent truffle pigs with Unity ML-Agents.

āš Important!āš 

šŸ‘‰The ENABLE_TENSORFLOW and Adding TensorFlowSharp are no longer necessary.

  • Unity updated ML-Agents to version 0.7.0 on February 26th, 2019 and thereā€™s a small change that affects this tutorial. It now uses Unity Inference Engine. You should be able to skip the ENABLE_TENSORFLOW step.

  • As of August 2nd, 2019, Unity has updated ML-Agents again. If you are using version 0.9, you may need to update trainer_config.yaml to the latest format. (More details here)

  • After training, you will now have a .nn file instead of a .bytes file. This works the same way, you just drag it into your brain, uncheck ā€œControlā€ in the Academy, and press play to run inference.

Note: If your .nn file doesnā€™t work, try allowing it to fully complete training (donā€™t exit early with Ctrl + C). I had some .nn files fail with unhelpful errors when I didnā€™t let it go all the way.

Setup

As mentioned in the video, the first thing you'll need to do is follow the Installation instructions and the Basic Guide. These will get you up and running with Unity ML-Agents and ready to start the tutorial.

https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md

https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Basic-Guide.md

I highly encourage you to check out the ML-Agents Documentation, which will help you understand the project in more depth and provide a place to discuss issues that are not specific to the pig project.

https://github.com/Unity-Technologies/ml-agents/tree/master/docs

3d Mesh Assets and Code

The free assets you will need for this project are here:

https://gumroad.com/l/NTzXT šŸ‘ˆ $0+ on Gumroad means you can get them *completely for free* by typing in a 0.

(however, if you want to give extra support, youā€™ll make me feel warm and fuzzy inside. šŸ˜ƒ)

ML-Agents Code

In this video, I'm using Release 0.6, which you can get here:

https://github.com/Unity-Technologies/ml-agents/releases/tag/0.6.0

The latest version is likely very similar, but if you have trouble, you can always roll back to 0.6.

Helpful Additions

Training Command

The command I used to train (in my Anaconda Prompt) with curriculum was:

    mlagents-learn config/trainer_config.yaml --curriculum=config/curricula/pig/ --run-id=pig_tutorial_01 --train

Note: If you get an error that a parameter is not present in the Environment, make sure to add Reset Parameters for "num_truffles", "num_stumps", and "spawn_range" in the Pig Academy.

Updates!


AI Flight with Unity ML-Agents

You know whatā€™s a bummer? YouTube videos canā€™t be updated. If you want an up-to-date, end to end, tutorial, we created a very affordable AI Flight course on Udemy. Itā€™ll teach you how to create a complete airplane racing game with ML-Agents! On top of that, by paying a little bit for it, youā€™ll support our future work. ā¤

Contact

You can reach out to me at @aktwelve on Twitter or connect with me on LinkedIn.

For future updates