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.
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.
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.
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.
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.