Out of interest in learning how machine learning works at the code level, I started building a firearm detector. There are plenty of libraries which detect a firearm, for instance, this one. I wanted to do it in Ruby and not detect just "a gun" but what kind of firearm. Why Ruby? Because it's the language I know the best right now. I don't want to have to learn yet another language, like python, just for this task. Maybe in the future.
I want to detect if the firearm is a rifle, a shotgun, a pistol, a revolver, a machine gun, and a sub-machine gun. In order to get started, I need a clear way to classify each weapon. I took the UNODC Firearms classifications and started from there. Second, this was also an excuse to try out the Nvidia Jetson Nano, rather than using a pay-per-hour cloud platform. The Jetson Nano runs Ubuntu 18.04 LTS, so 99% of setup and running is straight forward. The Jetson comes with a demo using the ImageNet libraries to let you see how it all works without a line of code.
The first task was to get the ruby tensorflow libraries working on the Jetson. This was non-trivial and took a few tries. I think I have it working correctly now. The second task, which really should've been the first, was to build a library of images of each type of firearm. I setup directories on the filesystem and just started using google/bing/ddg image search to find as many unique images of each type of firearm. This took the longest. In fact, I'm still going at it to better train the algorithm. As I've learned, 90% of the challenge of building accurate ML libraries is in the data. Part of me feels I should just outsource this via Upwork or Mechanical Turk and let the humans join me in sorting images into the correct directories. The code is really simple. Here's a sample of the ruby tensorflow API.
I'm not ready to publish anything yet, because the classification is still in the .60-80s range of accuracy, but it's getting better as I have time to work on it.
I expected this to be a one week project, but it's turned out to take longer. The first setback was my poor choice in microSD cards. The card failed and I lost everything on it, the operating system, the image libraries, the code, etc. I had to start over from scratch. For what it's worth, the choice of sd card matters both in speed and reliability. The second reason is just finding dedicated time to swap all this knowledge back into my brain again and work on it.
Nonetheless, the project is making progress and I'll post more as I have more to share.