Unity ML-Agents Tutorial | AI Truffle Pigs! 🐷

👇 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 and there’s a small change that affects this tutorial. It now uses Unity Inference Engine. I think everything else is pretty much the same, but you should be able to skip the ENABLE_TENSORFLOW step.

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 assets you will need for this project are here:
https://immersivelimit.page.link/PigMeshes
Updated Code: https://immersivelimit.page.link/PigCodeUpdate1
Original Code: https://immersivelimit.page.link/PigCode

Side note: I modeled all of the meshes in Blender. 😃

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

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!

Contact

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

For future updates