<jupyter_start><jupyter_text>Viola-Jones Example  Prerequisits Install viola-jones package by running:    pip install -e   Imports<jupyter_code>import violajones.IntegralImage as ii
import violajones.AdaBoost as ab
import violajones.Utils as utils
from IPython.core.display import Image, display<jupyter_output><empty_output><jupyter_text>Config<jupyter_code>pos_training_path = 'trainingdata/faces'
neg_training_path = 'trainingdata/nonfaces'
pos_testing_path = 'trainingdata/faces/test'
neg_testing_path = 'trainingdata/nonfaces/test'

num_classifiers = 20
# For performance reasons restricting feature size
min_feature_height = 4
max_feature_height = 10
min_feature_width = 4
max_feature_width = 10<jupyter_output><empty_output><jupyter_text>Load images<jupyter_code>print('Loading faces for training..')
faces_training = utils.load_images(pos_training_path)
faces_ii_training = list(map(ii.to_integral_image, faces_training))
print('..done. ' + str(len(faces_training)) + ' faces loaded.\n\nLoading non faces..')
non_faces_training = utils.load_images(neg_training_path)
non_faces_ii_training = list(map(ii.to_integral_image, non_faces_training))
print('..done. ' + str(len(non_faces_training)) + ' non faces loaded.\n')

print('Loading faces for testing..')
faces_testing = utils.load_images(pos_testing_path)
faces_ii_testing = list(map(ii.to_integral_image, faces_testing))
print('..done. ' + str(len(faces_testing)) + ' faces loaded.\n\nLoading test non faces..')
non_faces_testing = utils.load_images(neg_testing_path)
non_faces_ii_testing = list(map(ii.to_integral_image, non_faces_testing))
print('..done. ' + str(len(non_faces_testing)) + ' non faces loaded.\n')<jupyter_output>Loading faces for training..<jupyter_text>Learn (boost) classifiers (Haar-Like features)<jupyter_code># This will take a while
classifiers = ab.learn(faces_ii_training, non_faces_ii_training, num_classifiers, min_feature_height, max_feature_height, min_feature_width, max_feature_width)<jupyter_output>Creating haar-like features..
..done. 49122 features created.

Calculating scores for images..<jupyter_text>Testing<jupyter_code>print('Testing selected classifiers..')
correct_faces = 0
correct_non_faces = 0
correct_faces = sum(utils.ensemble_vote_all(faces_ii_testing, classifiers))
correct_non_faces = len(non_faces_testing) - sum(utils.ensemble_vote_all(non_faces_ii_testing, classifiers))

print('..done.\n\nResult:\n      Faces: ' + str(correct_faces) + '/' + str(len(faces_testing))
      + '  (' + str((float(correct_faces) / len(faces_testing)) * 100) + '%)\n  non-Faces: '
      + str(correct_non_faces) + '/' + str(len(non_faces_testing)) + '  ('
      + str((float(correct_non_faces) / len(non_faces_testing)) * 100) + '%)')<jupyter_output>Testing selected classifiers..
..done.

Result:
      Faces: 209/279  (74.91039426523297%)
  non-Faces: 98/215  (45.58139534883721%)
{'fraction_non_alphanumeric': 0.12169680111265646, 'fraction_numerical': 0.022253129346314324, 'mean_word_length': 6.71313672922252, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '23623', 'license': 'MIT', 'n_tokens_mistral': 1042, 'n_tokens_neox': 983, 'n_words': 170, 'path': '.ipynb_checkpoints/Viola-Jones Example-checkpoint.ipynb', 'repo_name': 'mogolola/Viola-jones_face_detector', 'size': '2876'}