Deep learning cat prey detector

We’ve all been able to check on our kitties’ outdoor activities for a while now, thanks to motion-activated cameras. And the internet’s favourite cat flap even live-tweets when it senses paws through the door.

A nightvision image of a cat approaching a cat flap with a mouse in its mouth

“Did you already make dinner? I stopped on the way home to pick this up for you.”

But what’s eluded us “owners” of felines up until now is the ability to stop our furry companions from bringing home mauled presents we neither want nor asked for.

A cat flap bouncer powered by deep learning

Now this Raspberry Pi–powered machine learning build, shared by reddit user u/eee_bume, can help us out: at its heart, there’s a convolutional neural network cascade that detects whether a cat is trying to enter a cat flap with something in its maw. (No word from the creators on how many half-consumed rodents the makers had to dispose of while training the machine learning model.)

The neural network first detects the whole cat in an image; then it hones in on the cat’s maw. Image classification is performed to detect whether there is anything in or around the maw. If the network thinks the cat is trying to smuggle caught contraband into the house, it’s a “no” from this virtual door bouncer.

The system runs on Raspberry Pi 4 with an infrared camera at an average detection rate of  around 1 FPS. The PC-Val value, representing the certainty of the prey classification => prey/no_prey certainty threshold, is 0.5.

The home made set up including small camera lights and sensors

The infrared camera setup, powered by Raspberry Pi

How to get enough training data

This project formed Nicolas Baumann’s and Michael Ganz’s spring semester thesis at the Swiss Federal Institute of Technology. One of the problems they ran into while trying to train their device is that cats are only expected to enter the cat flap carrying prey 3% of the time, which leads to a largely imbalanced classification problem. It would have taken a loooong time if they had just waited for Nicolas and Michael’s pets to bring home enough decomposing gifts.

Lots of different cats faces close up, some with prey in their mouths, some without

The cutest mugshots you ever did see

To get around this, they custom-built a scalable image data gathering network to simplify and maximise the collection of training data. It features multiple distributed Camera Nodes (CN), a centralised main archive, and a custom labeling tool. As a result of the data gathering network, 40GB of training data have been amassed.

What is my cat eating?!

The makers also took the time to train their neural network to classify different types of prey. So far, it recognises mice, lizards, slow-worms, and birds.

Infrared shots of one cat while the camera decides if it has prey in its mouth or not

“Come ooooon, it’s not even a *whole* mouse, let me in!”

It’s still being tweaked, but at the moment the machine learning model correctly detects when a cat has prey in its mouth 93% of the time. But it still falsely accuses kitties 28% of the time. We’ll leave it to you to decide whether your feline companion will stand for that kind of false positive rate, or whether it’s more than your job’s worth.

20 comments

eee_bume avatar

Thanks for the awesome blog post!!! I’ll link my repository with the code as soon as I’ve got it done in the comments here!

eee_bume avatar

Sorry for the late response. I’m in the middle of my exam-season, so the ReadMe hasn’t been done yet, I’ll get to it as soon as I can. Source code can be found at:

https://github.com/niciBume/Cat_Prey_Analyzer

Aiden ralph avatar

Hi I have a 100% working one for my cat. It doesn’t use deep learning.
It works on a pi 3 and I’m trying to get it to work on a pi zero and to be used on every cat. I had to overcome a lot of obstacles to get it this good. It works a lot different to yours!

Anders avatar

Excellent exercise. Another use that springs to mind is to identify cats in the garden, so gardeners who need to prevent cats from digging around amongst their plants can use it to trigger a water jet to scare the cat off.

eee_bume avatar

That would be a good use and it would be totally doable by using just a subsystem of this project. As it includes a cat classifier that is capable of detecting cats at 2 FPS. I also taught about an object detector that detects cats and cars and would trigger a traffic light such that my cats are more safe ;P

Rob avatar

That’s just what I was searching for! I want to keep the cats out (humanely!) and stop them from killing birds but I still want to encourage other mammals (squirrels, hedgehogs etc)…so I need some means of distinguishing between the two! Looks like I’m on a journey of AI discovery!

Anil avatar

That’s cool…

Atul Host avatar

I don’t have a cat. Can we make this for my doggo?

eee_bume avatar

Sure… But does your dog try to bring home prey? ;P

Ashley Whittaker avatar

Depends how big your cat-flap is ?‍♀️

Atul Host avatar

Just very close to it, I think I have to train her little more.

hasnain avatar

thats a good post i like it very much
keep itt up

Bruce Mardle avatar

It’s been done before (though not necessarily on a Raspberry Pi) at least twice before.

eee_bume avatar

Hi!
It is true that there have been other deep learning prey detection approaches for cats such as for example “The AI powered CatFlap of an Amazon employee”. Yet these approaches (to my knowledge) are trained on a specific cat in its specific environement. This system aims to solve the objective of general cat prey detection. Thus it has to have general knowledge of what a cat is, how its snout looks like etc. From a ML perspective general and specific objectives are very different tasks, as far as I know, this is the first approach of general cat prey detection.
Cheers

swisscore avatar

Hello I have 2 cats and i’m really interested by your work, but I don’t understand how to do exactly from the begining

eee_bume avatar

Hey Swisscore
I’m the developper of this system. If you want to know on how to get it running you can message me trough reddit ;)

Ajay Sharma avatar

One of the best blogs that i have read still now. Thanks for your contribution in sharing such a useful information. Waiting for your further updates.
what is deep learning?
Best Artificial Intelligence & Big Data In Pune With Placement

Pat avatar

The original: joakimsoderberg.github.io
Catcierge by JoakimSoderberg

Kristian avatar

Which RPi 4 model did you use for this project?

eee_bume avatar

RPI4 Model B/4GB

Comments are closed