Tracking Wildlife With Tensorflow - Setting Up an ML Environment on a Mac
A friend of mine set up a motion-activated camera on a solar panel, so I decided to do a little machine learning on it. I built an app that downloads the videos, splits them up into images, classifies the image, and then saves that info to a text file and posts to a discord channel about it. Future improvements include a feedback button so that a human can help train the model by flagging incorrect images and confirming correct ones. This feature will add those images to a training set because my training set was, frankly, not that good. There's just not that much out there for West Virginia wildlife!
First things first. I am in a slightly weird position in that I have the fanciest new Mac chip... but not enough of an internet connection to stay connected to Colab long enough to train a model. So first I had to wade through all the headaches around conflicting architectures. Turns out tensorflow needs arm architecture, but motplotlib needs x86? But then when I found a StackOverflow post on how to fix that via the virtual environment I really should already have been running, I ran into an "illegal operation" error.
Ultimately I had to install conda in order to install the prereqs in order to install tensorflow metal as per this excellent article.
I elected to run everything in a python file instead of a jupyter notebook both because that's just my preferred method and because I liked the errors I got better.
For example, some Keras methods aren't implemented in tensorflow-metal yet. Luckily, this is solved by explicitly setting a device that can handle it. Wrap anything that needs methods like RandomFlip in the block
with tf.device('/cpu:0'):
(Thanks to This StackOverflow post for that one)
I more or less just adapted the tensorflow example code because it's fast, it's easy, and it works. I think people get caught up in the "best" option when right now, for these kinds of hobby projects, the perfect really is the enemy of the good.