Many cat owners have awoken to the sound of frenzied scrambling across the floor as their furry feline friend chases the mouse it snuck into the house in the middle of the night. Or looked up to find their pet staring down with those adorable big round eyes at the dead little fledgling it has deposited beside your pillow as a “ present. ”

Amazon Sr. Product Manager Benjamin Hamm had just such a problem with his handsome cat “Metric,” a keen hunter who brings a catch into the house roughly every 10 days. Three in the morning is his favorite time. “Sometimes the animals he brings in are dead, sometime they are just badly wounded, in which case I have to euthanize a small animal in the middle of the night and try to go back to sleep…”

Hamm addressed the problem by learning to code, and shared the ML solution he developed in a recent and amusing Ignite Seattle talk, “Cats, Rats, A.I., Oh My!”

Hamm says solutions such as bells on Metric’s collar or banishing him outside for the night did not work, and so he explored ways to empower his cat door as a gatekeeper. It was easy to install the electronic kit Arduino to lock the cat door, but how to make it lock selectively: only when Metric was trying to bring in prey? That was when machine learning knocked at the door. Hamm mounted an Amazon DeepLens camera above the cat door and trained his system to determine whether Metric coming in “hot” with a rodent in its mouth. If so, Arduino would automatically lock the cat door for 15 minutes — long enough for Metric to reconsider his unwelcome gift and come back later, “clean.”

It took Hamm months to gather and hand-label 23,000 images of Metric coming and going with and without prey, “I’m like a tech bro version of the crazy cat lady!” He used the online ML service Sagemaker to train a model with three stages. The first stage is to identify “Is there a cat?” It then then asks “Is the cat coming or going?” If the cat is trying to come in, then the last stage is to ask “Is the cat coming in for a snack, or with a snack?” Hamm says the whole screening process takes less than two seconds.

If prey is detected in Metric’s mouth the door will lock, Hamm will receive evidence pictures of “serial killer” Metric’s bad deed; and the Audubon Society will receive a donation.

…but could cats hack the system?

Hamm says in five weeks of use the program has only unfairly locked Metric out one time out of 180 innocent entries, while the system successfully blocked a prey-laden Metric five times out of six attempts.

Although the ML model creation process was not easy for a first-timer, Hamm was able to persevere thanks to Metric: “Every time my motivation was getting kind of low, he brought in fresh, horrifying thing, and got me right back there!”

Although we applaud the creative use of ML, the Audubon Society recommends bright- or bell-collaring cats who go outside, or keeping them indoors.