FisherFace model training fails when missing training images (Bug #2253)
The python demo in samples/python2/facereco_demo.py will fail with this error:
cv2.error: /home/vagrant/dl/opencv/modules/core/src/matrix.cpp:291: error: (-215) 0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols in function Mat
inside the call to model.train() if you change it to use FisherFace instead of EigenFace and point it to a directory of training data where many of the subdirectories are missing training images. (Why would you do this, I hear you ask... My pre-processing code rejected a bunch of images but left the directories in place.) So the labels are somewhat sparse. Removing the empty directories fixes the problem.
This is with unreleased code not sure if it's 2.4.3 branch or 2.5.0 branch -- git commit 8c3984c5ff290deb02beae6a31a5cfe89979e79e.
read_images method is really simple. It was just intended to show how to read image data from your file system, because a lot of people have problems with the CSV file in the C++ demos. I'll (1) add a test to
read_images, that'll check if the directory is empty and (2) a
read_csv method, so you can also read a list with Comma Separated Values, that consists of
- Category set to python bindings
- Estimated time set to 2.00
- Assignee set to Philipp Wagner
If I do this in the demo on the labels (y) and a FisherFaces model it works as expected:
# Now read in the image data. This must be a valid path! [X,y] = read_images(sys.argv) if len(sys.argv) == 3: out_dir = sys.argv y = np.asarray(y) + 1
What input data are you using?
There is dependency between number of training images and number of unique labels.
If N -- number of training images and C -- number of unique labels,
It should be N == C (one training image per person) or N >= 2C-1.
Internally it is because PCA keeps N-C components
PCA pca(data, Mat(), CV_PCA_DATA_AS_ROW, (N-C));
And then LDA tries to take C-1 components
_eigenvalues = Mat(_eigenvalues, Range::all(), Range(0, _num_components));
_eigenvectors = Mat(_eigenvectors, Range::all(), Range(0, _num_components));