LogoLogo
  • Home
  • Projects
  • About
  • Contact

Unity Machine Learning and a Good Riddance to 2020

Devon O. · December 30, 2020 · Life, Unity3D · 0 comments
1

So it’s been just over a year since my last post here. As you may imagine, I’ve had a bit on my mind over that time though. I don’t think it’s a very controversial thing to say, that 2020 has been the suckiest year in my life time.

Like many others, I have been working from home since March. I remember 12 March packing up a desktop, laptop, monitor and a few other bits and bobs thinking to myself, “This sure seems like a lot of overkill considering we’ll be back in the office in a week or two.” Psych! Should’ve bewared those ides.

Over the Christmas holiday though, I picked up a new computer for my birthday and started digging into Unity3D machine learning. Just yesterday, I sat down and thought I’d get a kart that could follow a track. I copied the cart and cart code from the Unity Karting Microgame project (which does have it’s own ML code and agents – but I completely ignored that to figure it out on my own), found these fantastic race track assets, watched a few youtube video tutes, and finally came up with this:

After getting that working, I then created a new track and used the same .onyx file brain with no additional training and voila – my little artificially intelligent go-kart dude had, indeed, learned how to follow a track and not just drive in circles.


For my own benefit, I thought I’d gather together some of the most used/useful Unity ML cli commands, but others may find this helpful as well.

SETUP

python -m venv NAME_OF_ENVIRONMENT

Run this inside your project directory to create a new virtual environment in which to run your machine learning agent scripts for whatever project you’re working on.

activate

Run this inside your virtual environment Scripts directory to to in order to activate your environment.

python -m pip install –upgrade pip

After activating your virtual environment, run this inside your project directory to upgrade your python package manager.

pip install torch==1.7.0

Still inside your active environment install pytorch 1.7.0. Of course, this version may change later, but this is good for now.

pip install mlagents

Install the Unity mlagents python package.

TRAINING

mlagents-learn [path/to/config.yaml] [–run-id=ID] [–initialize-from=OLD_ID] [–force/–resume]

This will begin the training session and prompt you to hit play in the Unity editor. You can use a custom .yaml file for config, but if one is not specified, a default will be given.  A run id isn’t necessary, but should be used. Just create an id to identify the current training session like Kart_1 or whatever. Initialize will start the training based off an old training session with the name OLD_ID (or whatever you named the old session). If the id of this session has been used before, use –force to start it from the beginning or –resume to pick up where you left off.

DATA

tensorboard –logdir results

run this inside the active virtual environment Scripts directory. This will start up TensorBoard and let you know what port it’s running on. You can then open up your localhost to that port in a browser and view some nice graphs showing how the training has went, including the cumulative reward (should be going up) and episode length (should also be going up) for your training sessions.


I may add more commands later as I use more and grow more accustomed to them – but this is enough to get a project up and running.

I hope everyone stays safe out there. Wear a mask. And, hey, 2020, don’t let the door hit you in the ass on the way out.

  Facebook   Pinterest   Twitter   Google+
aimachine learning
  • Website Generation Tool Take II
    December 29, 2008 · 53 comments
    10961
    4
    Read more
  • Liquid On Screen Effect
    February 24, 2019 · 0 comments
    I really wasn't sure what to call this Unity3D post processing effect, but it's
    2709
    15
    Read more
  • Game Development Tips from the Trenches of PopCap
    August 01, 2011 · 5 comments
    3676
    5
    Read more

Leave a Comment! Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
  • Luca G on Unity Ripple or Shock Wave Effect
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2017 Devon O. Wolfgang