i have some questins about chapter7

81 views
Skip to first unread message

goodw...@daum.net

unread,
Jan 10, 2017, 2:44:17 AM1/10/17
to OpenCV with Python Blueprints
Hi I am korean.
I'm studying your book.
You should understand english wrong.
There is a problem with Chapter 7.
I was writing under the note

"" "OpenCV with Python Blueprints

    Chapter 7: Learning to Recognize Emotion in Faces
  
     An app that combines both face detection and face recognition, with a
     Focus on recognizing emotional expressions in the detected faces.
  
     The process flow is as follows:
     * 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".
     * 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".
     * Run the GUI in Testing Mode to apply the pre-trained MLP classifier
       To the live stream of the webcam.
 "" "

Test button can be clicked. So I Implement python train_test_mlp.py
So errors such as photographs.
Help me!
Auto Generated Inline Image 1

Michael Beyeler

unread,
Jan 10, 2017, 9:47:45 PM1/10/17
to OpenCV with Python Blueprints
Hi there!

You are doing everything right so far. However, I believe you are using old code. Perhaps you are using the code that originally came with the Packt book? The reason you are seeing this error is because there is a bug in chapter7/classifiers.py.

The quick-and-dirty way to fix this is to change the constructor of class MultiLayerPerceptron (chapter7/classifiers.py, around line 196) by adding:
self.mode = "one-vs-all"

A better solution would be to download the latest code from my GitHub profile. It has a lot more bug fixes and improvements, and I keep making changes to it. This might help you especially on Raspberry Pi.
To get the latest code, open a terminal and type:
$ cd ~
$ git clone https
://github.com/mbeyeler/opencv-python-blueprints
$ cd opencv
-python-blueprints/chapter7
$ python chapter7
.py

etc.
You might have to install git first.

Best,
Michael

goodw...@daum.net

unread,
Jan 17, 2017, 2:01:04 AM1/17/17
to OpenCV with Python Blueprints


2017년 1월 11일 수요일 오전 11시 47분 45초 UTC+9, Michael Beyeler 님의 말:
Hi there!

You are doing everything right so far. However, I believe you are using old code. Perhaps you are using the code that originally came with the Packt book? The reason you are seeing this error is because there is a bug in chapter7/classifiers.py.

The quick-and-dirty way to fix this is to change the constructor of class MultiLayerPerceptron (chapter7/classifiers.py, around line 196) by adding:
self.mode = "one-vs-all"

A better solution would be to download the latest code from my GitHub profile. It has a lot more bug fixes and improvements, and I keep making changes to it. This might help you especially on Raspberry Pi.
To get the latest code, open a terminal and type:
$ cd ~
$ git clone https
://github.com/mbeyeler/opencv-python-blueprints
$ cd opencv
-python-blueprints/chapter7
$ python chapter7
.py

etc.
You might have to install git first.

Best,
Michael

I solved the problem.
Thanks for helping solve the problem!!

goodw...@daum.net

unread,
Jan 17, 2017, 2:48:37 AM1/17/17
to OpenCV with Python Blueprints


2017년 1월 17일 화요일 오후 4시 1분 4초 UTC+9, goodw...@daum.net 님의 말:
but  Test button click is possible, but there is no response in test mode. 

Michael Beyeler

unread,
Jan 18, 2017, 5:42:54 PM1/18/17
to OpenCV with Python Blueprints
Let me make sure I understand correctly.

I assume you have done the following:
  • Run chapter7.py in training mode with a webcam attached. Make sure you can see your face and that there is a green rectangle drawn around it. Click "Take Snapshot" and make sure the terminal reads "Added sample to training set". Repeat for all emotions (neutral, happy, sad, surprised, angry, disgusted). Make sure to smile when "happy"! ;-) Repeat until you have at least 10-20 samples for each class, or 50-100 total training samples.
  • Run train_test_mlp.py. Make sure the script runs to completion. Make sure train accuracy is as close to 1.0 as possible. Make sure the script created a file params/mlp.xml.
  • Run chapter7.py again, but this time in testing mode (by clicking the button). Make sure you can see your face and that there is a green rectangle drawn around it. Whenever the rectangle shows up, the emotion should be drawn above it (e.g., "angry").
If no text shows up, it means your face couldn't be classified. There are a few possibilities for that:
  • Your training set isn't good/large enough. Try creating a larger training set, and make sure all emotions are included. Make sure you twist and turn your head (just a little bit) to make the learning more robust to variation. Make sure you have your eyes open (the more the better). If the eye cascade failed, there should be a comment on the terminal: "Could not align head (eye detection failed?)".
  • Either the face cascade or the eye cascade failed. The eye cascade might fail if you have glasses or when lighting is poor. Try removing your glasses and repeating the training. Make sure your face is clearly lit. Try opening your eyes more.
Best,
Michael

Ali Ashraf

unread,
Feb 1, 2017, 4:41:51 AM2/1/17
to OpenCV with Python Blueprints
Hi there! ,
i have this problem when i try to run train_test_mlp , what is the problem and what should i do ??
z.jpg
para folder.jpg

Michael Beyeler

unread,
Feb 1, 2017, 12:17:54 PM2/1/17
to OpenCV with Python Blueprints
Hi Ali,

It looks like your `datasets/faces_training.pkl` contains only 3 training samples. That is not enough; I would say you need at least 50-100!

So go back to step 1 in my outline below (running chapter7.py in training mode) and add training samples by clicking "Take Snapshot". Make sure to select different facial expressions in the GUI, and repeat until you have a good number of training samples. It's also important to have training samples for all classes (e.g., smiling, neutral, etc.).

Then run `train_test_mlp.py` again and the error should go away.

Best,
Michael
Message has been deleted

Michael Beyeler

unread,
Feb 28, 2017, 1:56:30 AM2/28/17
to OpenCV with Python Blueprints
Hi, it seems you do not have OpenCV Version 1 (the cv module) installed.

Do any of the other chapters work?
Which version of OpenCV are you using?

Also, how exactly did you install OpenCV?
From the screenshot I'm guessing that you're on Windows. I wrote this blog post a while ago on how to install OpenCV on Ubuntu: http://www.askaswiss.com/2016/01/how-to-install-opencv-3-1-python-ubuntu-14-04.html. You might still find it helpful by looking at Step 0: Installing opencv via Python Anaconda. This works on Windows, and is by far the easiest solution!

If you still have trouble with installation, please open a new post on this forum.

Best,
Michael



On Monday, February 27, 2017 at 11:47:54 PM UTC-7, 상범박 wrote:
I am running chapter7.py.
I had installed opencv.However, these errors occur.
There is a lot of difficulties on the computer.
Can you help me?

상범박

unread,
Feb 28, 2017, 2:00:15 AM2/28/17
to OpenCV with Python Blueprints
1.PNG
Reply all
Reply to author
Forward
0 new messages