mbeyeler / opencv-python-blueprints

M. Beyeler (2015). OpenCV with Python Blueprints: Design and develop advanced computer vision projects using OpenCV with Python, Packt Publishing Ltd., ISBN 978-178528269-0.
GNU General Public License v3.0
292 stars 184 forks source link

could not align head #20

Closed yogeshAhireSuresh closed 6 years ago

yogeshAhireSuresh commented 7 years ago

i am using opencv2 and python version 3.5.2 i had made some changes and now got some error as follows:

Warning: Testing is disabled Could not find data file datasets/faces_preprocessed.pkl Could not align head (eye detection failed?)

mbeyeler commented 7 years ago

Hi, in order to get a file "datasets/faces_preprocessed.pkl" you need to follow the following steps (described here):

  1. Run the GUI in Training Mode to assemble a training set. Upon exiting the app will dump all assembled training samples to a pickle file "datasets/faces_training.pkl".
  2. Run the script train_test_mlp.py to train a MLP classifier on the dataset. This file will store the parameters of the trained MLP in a file "params/mlp.xml" and dump the preprocessed dataset to a pickle file "datasets/faces_preprocessed.pkl".
  3. Run the GUI in Testing Mode to apply the pre-trained MLP classifier to the live stream of the webcam.

In Step 1, when you take a snapshot, the algorithm is trying to find the location of your head and eyes using some default OpenCV Haar cascade classifiers. The eye cascade I used (see here) can sometimes be a bit finicky... Make sure your scene is well-lit, don't wear your glasses, and try to make big googly eyes. :wink:

You might be able to find a better cascade classifier here.

Best, Michael

yogeshAhireSuresh commented 7 years ago

Thank you for your reply, i tried running the changes, now it is working fine and it is creating the pkl file also but when i am running the train_test_mlp.py it is showing following error.

On Wed, Oct 25, 2017 at 3:34 AM, Michael Beyeler notifications@github.com wrote:

Hi, in order to get a file "datasets/faces_preprocessed.pkl" you need to follow the following steps (described here https://github.com/mbeyeler/opencv-python-blueprints/blob/master/chapter7/chapter7.py#L10 ):

  1. Run the GUI in Training Mode to assemble a training set. Upon exiting the app will dump all assembled training samples to a pickle file "datasets/faces_training.pkl".
  2. Run the script train_test_mlp.py to train a MLP classifier on the dataset. This file will store the parameters of the trained MLP in a file "params/mlp.xml" and dump the preprocessed dataset to a pickle file "datasets/faces_preprocessed.pkl".
  3. Run the GUI in Testing Mode to apply the pre-trained MLP classifier to the live stream of the webcam.

In Step 1, when you take a snapshot, the algorithm is trying to find the location of your head and eyes using some default OpenCV Haar cascade classifiers. The eye cascade I used (see here https://github.com/mbeyeler/opencv-python-blueprints/blob/master/chapter7/chapter7.py#L72) can sometimes be a bit finicky... Make sure your scene is well-lit, don't wear your glasses, and try to make big googly eyes. 😉

You might be able to find a better cascade classifier here https://github.com/opencv/opencv/tree/master/data/haarcascades.

Best, Michael

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mbeyeler/opencv-python-blueprints/issues/20#issuecomment-339148285, or mute the thread https://github.com/notifications/unsubscribe-auth/AfifuVoZuRRWWz3fNuROs_CYcSgz6l0Qks5svl7igaJpZM4QE_bz .

mbeyeler commented 7 years ago

Which error is that? The message didn't show up on GitHub Issues...

If you get errors in "train_test_mlp.py", make sure you have added multiple training samples from every class (happy, sad, etc.).

yogeshAhireSuresh commented 7 years ago

RESTART: C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py Loading data from datasets/faces_training.pkl Loaded 4 training samples Save preprocessed data to datasets/faces_preprocessed.pkl Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 42, in main train_method=cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP, AttributeError: module 'cv2.cv2' has no attribute 'ANN_MLP_TRAIN_PARAMS_BACKPROP'

it is the error

On Wed, Oct 25, 2017 at 10:25 PM, Michael Beyeler notifications@github.com wrote:

Which error is that? The message didn't show up on GitHub Issues https://github.com/mbeyeler/opencv-python-blueprints/issues/20...

If you get errors in "train_test_mlp.py", make sure you have added multiple training samples from every class (happy, sad, etc.).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mbeyeler/opencv-python-blueprints/issues/20#issuecomment-339397381, or mute the thread https://github.com/notifications/unsubscribe-auth/AfifualA4kD9yvA-fIehc3UztsvruuNzks5sv2gSgaJpZM4QE_bz .

yogeshAhireSuresh commented 7 years ago

i solved that error of mean in homebrew.py line no 139 (Just added m), the error was that in the code there was only one parameter and the parameter for mean was missing. but now i am getting an error for ANN_MLP as follows:

RESTART: C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py Loading data from datasets/faces_training.pkl Loaded 4 training samples Save preprocessed data to datasets/faces_preprocessed.pkl Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 42, in main train_method=cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP, AttributeError: module 'cv2.cv2' has no attribute 'ANN_MLP_TRAIN_PARAMS_BACKPROP'

please guide me.

On Wed, Oct 25, 2017 at 10:42 PM, Yogesh ahire yahire3388@gmail.com wrote:

RESTART: C:\Users\yahir\Downloads\opencv-python-blueprints- master\chapter7\train_test_mlp.py Loading data from datasets/faces_training.pkl Loaded 4 training samples Save preprocessed data to datasets/faces_preprocessed.pkl Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints- master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints- master\chapter7\train_test_mlp.py", line 42, in main train_method=cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP, AttributeError: module 'cv2.cv2' has no attribute 'ANN_MLP_TRAINPARAMS BACKPROP'

it is the error

On Wed, Oct 25, 2017 at 10:25 PM, Michael Beyeler < notifications@github.com> wrote:

Which error is that? The message didn't show up on GitHub Issues https://github.com/mbeyeler/opencv-python-blueprints/issues/20...

If you get errors in "train_test_mlp.py", make sure you have added multiple training samples from every class (happy, sad, etc.).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mbeyeler/opencv-python-blueprints/issues/20#issuecomment-339397381, or mute the thread https://github.com/notifications/unsubscribe-auth/AfifualA4kD9yvA-fIehc3UztsvruuNzks5sv2gSgaJpZM4QE_bz .

yogeshAhireSuresh commented 7 years ago

i solved the upper commented error also by adding ml like

train_method=cv2.ml.ANN_MLP_BACKPROP,

but now i am getting the following error while running train_test_mlp.py:

previously the code was :

initialize MLP

self.model = cv2.ANN_MLP()
self.model.create(layer_sizes)

error which i got is :

1-hidden layer networks Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 54, in main MLP = MultiLayerPerceptron(layerSizes, labels) File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\classifiers.py", line 221, in init self.model = cv2.ANN_MLP() AttributeError: module 'cv2.cv2' has no attribute 'ANN_MLP'

The changes i had did: self.model = cv2.ml.ANN_MLP_create(layer_sizes) // Its the code which is throwing error

the error i got again is:

Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 54, in main MLP = MultiLayerPerceptron(layerSizes, labels) File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\classifiers.py", line 221, in init self.model = cv2.ml.ANN_MLP_create(layer_sizes) SystemError: returned NULL without setting an error

On Wed, Oct 25, 2017 at 10:52 PM, Yogesh ahire yahire3388@gmail.com wrote:

i solved that error of mean in homebrew.py line no 139 (Just added m), the error was that in the code there was only one parameter and the parameter for mean was missing. but now i am getting an error for ANN_MLP as follows:

RESTART: C:\Users\yahir\Downloads\opencv-python-blueprints- master\chapter7\train_test_mlp.py Loading data from datasets/faces_training.pkl Loaded 4 training samples Save preprocessed data to datasets/faces_preprocessed.pkl Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints- master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints- master\chapter7\train_test_mlp.py", line 42, in main train_method=cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP, AttributeError: module 'cv2.cv2' has no attribute 'ANN_MLP_TRAINPARAMS BACKPROP'

please guide me.

On Wed, Oct 25, 2017 at 10:42 PM, Yogesh ahire yahire3388@gmail.com wrote:

RESTART: C:\Users\yahir\Downloads\opencv-python-blueprints-master\ chapter7\train_test_mlp.py Loading data from datasets/faces_training.pkl Loaded 4 training samples Save preprocessed data to datasets/faces_preprocessed.pkl Traceback (most recent call last): File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 68, in main() File "C:\Users\yahir\Downloads\opencv-python-blueprints-master\chapter7\train_test_mlp.py", line 42, in main train_method=cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP, AttributeError: module 'cv2.cv2' has no attribute 'ANN_MLP_TRAIN_PARAMS_BACKPROP'

it is the error

On Wed, Oct 25, 2017 at 10:25 PM, Michael Beyeler < notifications@github.com> wrote:

Which error is that? The message didn't show up on GitHub Issues https://github.com/mbeyeler/opencv-python-blueprints/issues/20...

If you get errors in "train_test_mlp.py", make sure you have added multiple training samples from every class (happy, sad, etc.).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mbeyeler/opencv-python-blueprints/issues/20#issuecomment-339397381, or mute the thread https://github.com/notifications/unsubscribe-auth/AfifualA4kD9yvA-fIehc3UztsvruuNzks5sv2gSgaJpZM4QE_bz .

yogeshAhireSuresh commented 7 years ago

sir, i am not able to solvethe ANN_MLP error, as i am using python 3.5.2 with opencv2. i created dataset with many snapshots for each emotion but i am having problem while running train_test_mlp script. the screenshot is attached.

On Wed, Oct 25, 2017 at 9:55 AM, Michael Beyeler notifications@github.com wrote:

Which error is that? The message didn't show up on GitHub Issues https://github.com/mbeyeler/opencv-python-blueprints/issues/20...

If you get errors in "train_test_mlp.py", make sure you have added multiple training samples from every class (happy, sad, etc.).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mbeyeler/opencv-python-blueprints/issues/20#issuecomment-339397381, or mute the thread https://github.com/notifications/unsubscribe-auth/AfifualA4kD9yvA-fIehc3UztsvruuNzks5sv2gSgaJpZM4QE_bz .

mbeyeler commented 7 years ago

It sounds like the layer_sizes variable has invalid format - have you tried printing it? It should be a NumPy array with the number of neurons in each layer np.array([n_input, n_hidden, n_output]).