Ask Your Question
4

The Integrated Catflap : Fine Tuning Cascade / Deep Learning

asked 2018-08-04 10:53:43 -0600

BigJinge gravatar image

updated 2018-08-06 21:13:50 -0600

Hi,

I've built into a stock catflap, a prey sensing Raspberry Pi OpenCV camera system that will check the underside of our cat's mouth and if cascade trained prey is detected, will lock the catflap so Fluffy can't come in with her murder present.

I've spent a number of months trying different positives / scaling / neighbours. Whilst I've been able to get it to lock for some detections such as eyes and tail of the mouse, it doesn't seem to pick up noses or the claws very well.

I trained it with 200 positives and over 9000 negatives.

The best I've gotten was with the HAAR cascade, with Scale factor of 1.01 and Min Neigh of 2.

I don't need to scale much as the cat always comes through at the same distance and the mouse / bird is virtually the same size. It's a positional thing if the mouse if facing forward rather than rear etc. Hence getting as many positional positives as possible.

What I don't understand is when I tested the cascade with the images it was trained with, you'd think it would pick them all out but it doesn't.

Any recommendations on how to fine tune the Scale and Neighbours or even the images going into the cascade?

I've put the cascades, positives and tests here. https://bit.ly/2OKdP43

You're welcome to use the positives in your projects.

Many thanks

Richard

edit retag flag offensive close merge delete

Comments

You might have better luck with a neural network. Check out this post.

Der Luftmensch gravatar imageDer Luftmensch ( 2018-08-05 08:21:23 -0600 )edit
1

In answer to the person who made the quote about the cascade being a binary classifier. The no cat, cat, cat with prey issue.

This was an issue before I cropped the images down as the fur of the cat and the fur of the mouse were being confused but that is a good point. I wanted to only put in features that are absolutely prey. This is why I didn't put in stock pictures of complete mice to train.

What I could do is for those images where there is a slight bit of cat, is black out that area only leaving the mouse and rerun the cascade.

Re the neural network, thanks. I had wondered if Tensorflow could help and I've worked with Adrian's code before plus he's a great help.

Great pointer.

Thanks

Richard

BigJinge gravatar imageBigJinge ( 2018-08-05 09:05:12 -0600 )edit

That's a deadly awesome project!!!

sjhalayka gravatar imagesjhalayka ( 2018-08-06 19:11:21 -0600 )edit

Thanks sjhalayka.

I started it a couple of years ago but due to life commitments have only spent 6 months or so on it total. Here is a link showing the electronics and outside of flap.

https://www.raspberrypi.org/forums/vi...

Richard

BigJinge gravatar imageBigJinge ( 2018-08-06 19:38:21 -0600 )edit

Have you tried the OpenCV feedforward back-propagation artificial neural network (aka plain vanilla ANN)?

sjhalayka gravatar imagesjhalayka ( 2018-08-06 19:50:40 -0600 )edit

I'm looking at neural nets now, so I'll add that to the list. :)

BigJinge gravatar imageBigJinge ( 2018-08-06 20:29:57 -0600 )edit

Cool. Let us know how it goes. Would you like to have some C++ source code or are you using Python?

sjhalayka gravatar imagesjhalayka ( 2018-08-06 20:45:48 -0600 )edit

I'm using Python.

BigJinge gravatar imageBigJinge ( 2018-08-06 21:53:19 -0600 )edit

The URL below has code for both binary and one-hot encoding, focusing on teaching the ANN how to solve the XOR problem. It doesn't take into account a loss function.

https://github.com/sjhalayka/python_o...

sjhalayka gravatar imagesjhalayka ( 2018-08-06 22:48:00 -0600 )edit

Thanks muchly.

BigJinge gravatar imageBigJinge ( 2018-08-07 19:59:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-08-06 18:04:59 -0600

Eduardo gravatar image

Here some information and pointers to train a neural network for object detection using TensorFlow on custom data.

Following are references I used to train with MobileNet SSD (using checkpoint weights) for one class on my data and locally (no cloud). I cannot guarantee that these instructions are optimal or the good way to do but it should work.


TensorFlow installation

See the official tutorial.

Installation should be quite easy, I did it on Ubuntu 16.04 using the virtualenv way. If you have a good nvidia GPU, it is worth the effort to install CUDA and cuDNN and install tensorflow-gpu.

What should be tricky is to install the latest display driver to be able to use the latest CUDA and cuDNN versions. On Ubuntu, you have to disable the X-server for instance and uninstall the drivers coming from the distribution I think. More information here: NVIDIA CUDA Installation Guide for Linux.

TensorFlow object detection API

  • Documentation are here and here
  • Installation instructions are here
  • New API (July 13, 2018) doc is here

Guide to train on custom data

  • This guide contains some useful information but uses now the legacy API (legacy since July 13, 2018)
  • The procedure is always the same: labelize your data, you can use LabelImg for that
  • Split your data into training and evaluation sets
  • Labels are in PASCAL VOC format, see this answer to setup the directories
  • Generate TFRecord data from XML annotation files
  • Change the parameters (num_classes, batch_size, fine_tune_checkpoint, train_input_reader, eval_config, eval_input_reader) in ssd_mobilenet_v1_coco.config for your desired network
  • Launch the training and the evaluation, see these instructions for the old API
  • Launch Tensorboard: tensorboard --logdir=${PATH_TO_MODEL_DIRECTORY} and open in a browser the following address: http://localhost:6006
  • You can then observe the loss curves and the results of the detection on your evaluation data

Export / Test


I have skipped some details to keep it short but all the information are available in the official documentation or in some tutorials. The procedure is always the same and once you know how to do it, it is quite straightforward.

edit flag offensive delete link more

Comments

Thanks, that's the great help.

I have been doing some reading about deep learning since posting the original question and given the physical space inside the catflap, I'm having to use a Pi Zero. Anything that would help the recognition run faster would be a ideal, so I'm looking a getting a Movidius NCS.

I can run it with the output from Tensorflow / Caffe. I did have a look to see if I could find pre-trained models of mice but I couldn't find one, so it looks like I will have to make one.

Deep learning is all new to me so getting used to frameworks, graphs and weights.

It's all good.

BigJinge gravatar imageBigJinge ( 2018-08-06 21:12:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-08-04 10:53:43 -0600

Seen: 706 times

Last updated: Aug 06 '18