ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
53.37k stars 13.48k forks source link

Runtime exception of the example face_recognition_svm.py #1145

Open caibf opened 4 years ago

caibf commented 4 years ago

Environment

Description

Runtime exception of the example face_recognition_svm.py in my environment. I use it to train multiple images for only one person.

What I Did

The tree structure of test data:

<svm_examples>/
   ├── <train>/
   │   ├── <person1>/
   │   │   ├── <somename1>.jpg
   │   │   ├── <somename2>.jpg
   │   │   ├──  ...
   │   ├── <person2>/
   │   │   ├── <somename1>.jpg
   │   │   ├── <somename2>.jpg
   └── ...
   ├── <test>/
   │   ├── <test_image1>.jpg
   │   ├── <test_image2>.jpg
   └── ...

The command I ran and the output:

> python face_recognition_svm.py
Training image: svm_examples/train\charley\charley_1.jpg
Training image: svm_examples/train\charley\charley_2.jpg
Training image: svm_examples/train\charley\charley_3.jpg
Training image: svm_examples/train\charley\charley_4.jpg
Training image: svm_examples/train\charley\charley_5.jpg
Training image: svm_examples/train\charley\charley_6.jpg
Training image: svm_examples/train\charley\charley_7.jpg
Traceback (most recent call last):
  File "facerec_from_picture_svm.py", line 45, in <module>
    clf.fit(encodings, names)
  File "C:\Program Files\Python36\lib\site-packages\sklearn\svm\_base.py", line
164, in fit
    y = self._validate_targets(y)
  File "C:\Program Files\Python36\lib\site-packages\sklearn\svm\_base.py", line
550, in _validate_targets
    " class" % len(cls))
ValueError: The number of classes has to be greater than one; got 1 class
lanzani commented 4 years ago

Hi! the SVM works with at least 2 sets. I suppose that you trained the model with only one face, in this case you have to put at least two face in the dataset.

Some starting resources: This is how SVM works: https://towardsdatascience.com/support-vector-machine-introduction-to-machine-learning-algorithms-934a444fca47 Or watch this video: https://www.youtube.com/watch?v=Y6RRHw9uN9o

Bye 👋