bytefish/facerec — pull request #17 by DrinkingGypsie (2013-07-31 10:29:50+00:00)
Title: Update simple_videofacerec.py

Hi playing around and noticed a little issue.

xrange(max(labels)) won't inlucde the last number! and hence len(list_of_labels) != len(subject_names) for our dict.

I ran into this issue if the subject detected was the last folder parsed for training, I ran into a Key Error, on self.model.subject_names[prediction].

set(labels) grabs our unique values. alternatively list(xrange(max(labels)+1)) would also work.

For example:
>>> labels = (0,0,0,0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
>>> list_of_labels = list(xrange(max(labels)))
>>> list_of_labels
[0, 1, 2]
>>> list_of_labels = set(labels)
>>> list_of_labels
set([0, 1, 2, 3])
>>> list_of_labels = list(xrange(max(labels)+1))
>>> list_of_labels
[0, 1, 2, 3]
>>>