0

I made a working face recognition program but from time to time it can: 1) Not detect a face / detect an extra non face as a face. 2) When it gets a familiar face he might recognize that it’s a new person / recognize that a new unfamiliar face is someone else.

These two problems of false positive and true negatives are due to the constants such as the in the cascade.detectMultiScale parameters: scaleFactor, minNeighbors, minSize, maxSize. And in the face_recognizer the num_components, threshold.

So my question is how can I find the optimal values for these parameters?

Yotam Hammer
  • 127
  • 1
  • 2
  • 8

1 Answers1

1

Experimentally, you have to do a grid search. So if you have the labels (correct values of the boxes etc.) you can do a grid search in a way that you define a set of hyperparameters that you want to finetune and check every possible combination of them to find the best one.

For example, in the face_recognizer you can try and experiment with threshold like this:

for threshold in [0.5, 0.6, 0.7, 0.8, 0.9]:
    for image in the trainset:
      res = face_recognizer(image, threshold=threshold)
      assert (res==label)

If you want to check more than one hyperparameter you can just add another for loop:

for param_1 in [value_1, value_2...]:
  for param_2 in [value_1, value_2...]:
    for image in the trainset:
      res = face_recognizer(image, threshold=threshold)
      assert (res==label)

You can add as many hyperparameters you want. You just have to save the average loss and error with the corresponding values of hyperparameters. That way you can select the best ones after the grid search and select the final model (parameters) with that.

Novak
  • 2,143
  • 1
  • 12
  • 22