12

I'm trying to train a model to detect the basic shapes like Circle, Square, Rectangle, etc. using Tensorflow. What would be the best input data set? To load the shapes directly or to find the edge of the image using OpenCV and load only the edge image.

We can detect shapes using OpenCV too. What would be the added advantage to use Machine Learning.

Sample images given for training the model.

Circle Detected using OpenCV Square detection

OpenCV User
  • 139
  • 1
  • 1
  • 8

2 Answers2

6

I would recommend starting with this guide for doing classification, not object detection: https://kiosk-dot-codelabs-site.appspot.com/codelabs/tensorflow-for-poets/#0

Classification is for one unique tag for one picture (99% square, 1%circle). Object Detection is for classification of several objects within the picture (x_min=3,y_min=8,x_max=20,y_max30, 99% square). Your case looks more like a classification problem.

You don't need the full Docker installation as in the guide. If you have Python 3.6 on your system, you can just do:

pip install tensorflow

And then jump to "4. Retrieving the images"

I had to try it out myself, so I downloaded the first 100 pictures of squares and circles from Google with the add-on "fatkun batch download image" from Chrome Web Store.

On my first 10 tests I get accuracy between 92,0% (0.992..) and 99,58%. If your examples are more uniform than a lot of different pictures from Google, you will probably get better results.

Punnerud
  • 7,195
  • 2
  • 54
  • 44
4

You may want to checkout objective detection in tensorflow. https://github.com/tensorflow/models/tree/master/research/object_detection There is a pre-trained model here http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_11_06_2017.tar.gz

One potential advantage of using neural nets to do the detection is that it can reduce the cpu cycles to calculate. This is useful on mobile devices. For example - the Hough transform https://en.wikipedia.org/wiki/Hough_transform is too expensive to calculate / but if a convolutional neural net was used instead - more possibilities open up for real time image processing.

To actually train a new model - see here https://www.tensorflow.org/tutorials/deep_cnn

johndpope
  • 5,035
  • 2
  • 41
  • 43
  • 1
    The link is 404 - should it now be this? https://github.com/tensorflow/models/tree/master/research/object_detection – Lee Goddard Sep 05 '19 at 08:55