Guidelines to select training images for ML model using CoreML 2 a case study

How to Build a Face Recognition App in iOS and train ML model using CoreML 2 – Part 3

Posted by Farooq Nasim Ahmad on March 12, 2019

We built and analysed several models in order to build a model with better accuracy. We have found that training data set plays a pivotal role in accuracy of model. We improved our data set on basis of our analysis.

First data set

We acquired face images of Einstein using STS Central Train Model feature. We acquired two kind of images. The first set contained all images of Einstein we named it “Einstein”, and the second set contained images of random people, we named it “Not Einstein”. In our “Einstein” data set we took about 165 images of Einstein that contains almost 90% black and white photos and 10% coloured photos. In our “Not Einstein” data set we took about 200 photos of both male and female persons. The amazing Train Model feature of STS Central extracted only images of faces. The “Not Einstein” data set contains almost all coloured photos.

Once we prepared model using CoreML 2 as next step we tested our model with various data sets. The first set of test images contains randomly selected black and white images of Einstein. Our model successfully recognised the photos with 90% accuracy. In second set of test images we give him random coloured images of human faces. This test set did not contain any image of Einstein. STS Central gives above 90% accurate results using our model.

In third test set of images we give random black and white human images. This test set also did not contain any image of Einstein. STS Central while acquiring images in real-time from computer screen provided 100% false positive results and declared all black and white images to be photos of Einstein.

The sizes of training and test images also varied a lot. They range from images of 100x100 pixels to 1200x1200 pixel facial images.

Second data set

In order to build a more accurate data set we followed following guidelines.

1. Balance number of images for each type of images. This means that if in our case we select 100 images of “Einstein”, “Not Einstein” should also contain 100 images. It should not be the case that we have 10 images of “Einstein” and “Not Einstein” contains 1000 images.

2. The minimum size of training image should be 299x299. If the size will be less than 299x299 the CoreML 2 will automatically scale it to 299x299 that will result in a blur image and inaccurate training data.

3. Training data should be comprehensive. In case we want to build a model that may recognize both coloured and black and white images of Einstein our training data for both “Einstein” and “Not Einstein” must contains both type of images. Same is true if we are required to recognize a face with a fixed camera that is supposed to be installed indoor. The training images should be acquired indoor. If we will use a model trained with indoor images with an outdoor camera the result will not be accurate.

4. Try adjusting the training parameters. When working with image data, double the maximum number of iterations in 1. the MLImageClassifierBuilder playground UI (the default value is 10).

We selected 100 images of Einstein all black and white and 100 images of random persons. STS Central extracted faces from both sets. We also modified STS Central to extract training faces only if the face size is greater than or equal to 299x299. Similarly, we modified our matching mechanism. We only pass a real-time extracted image to our model if its size is at least 299x299.

With our new data set we get above 90% accuracy for “Einstein” test data that contains all black and white photos. We also get 95% accuracy for “Not Einstein” test data that contains all black and white images of random people.