Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the code #18

Open
Diego430 opened this issue Sep 2, 2019 · 3 comments
Open

Problem with the code #18

Diego430 opened this issue Sep 2, 2019 · 3 comments

Comments

@Diego430
Copy link

Diego430 commented Sep 2, 2019

[3 1 1 0 1 2 1 3 3 0 1 2 2 1 1 1 1 3 2 0 3 0 1 1 1 1 1 2 1 3 1 0 1 3 0 0 3
3 1 0 1 0 1 2 0 3 3 3 0 0 3 1 1 1 0 1 0 3 3 0 3 3 3 1 2 0 0 0]
(0, 0, 0, 0, 1, 0, 0, 3, 3, 0, 2, 0, 2, 0, 0, 0, 2, 3, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 0, 3, 0, 0, 3, 3, 1, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 0, 1, 2, 1, 0, 1, 0, 3, 0, 0, 3, 0, 3, 0, 0, 0, 0, 0)
Accuracy:0.574

Confusion matrix: [[18 0 0 0]
[14 7 3 1]
[ 6 0 1 0]
[ 5 0 0 13]]
Traceback (most recent call last):
File "emotionRecognition_cnn.py", line 63, in
cnn_example()
File "emotionRecognition_cnn.py", line 33, in cnn_example
predicted = cnn.predict_one(feature)
File "/home/diego/Desktop/progetto/cnn_emotionrecognition/dnn.py", line 98, in predict_one
return np.argmax(self.model.predict(np.array([sample])))
File "/home/diego/.local/lib/python3.7/site-packages/keras/engine/training.py", line 1149, in predict
x, _, _ = self._standardize_user_data(x)
File "/home/diego/.local/lib/python3.7/site-packages/keras/engine/training.py", line 751, in _standardize_user_data
exception_prefix='input')
File "/home/diego/.local/lib/python3.7/site-packages/keras/engine/training_utils.py", line 128, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (1, 198, 39)

The code used is:
python3 cnn_examples.py

The envinronment is created via "pip3 install -r requirements.txt" as you suggested

I don't know what this problem is, can you help me?
Thanks

@leileileidan
Copy link

leileileidan commented Dec 17, 2019

Hello! I have solved this problem as follows:
In the file of cnn_examlpe.py .Before model.predict_one(),reshapes the shape of the results of get_feature_vector_from_mfcc(filename, flatten=to_flatten) :
mfcc = get_feature_vector_from_mfcc(filename, flatten=to_flatten)
mfcc = mfcc.reshape(mfcc.shape[0], mfcc.shape[1], 1)
print('prediction', model.predict_one(mfcc), 'Actual 3')

@Mahanotrahul
Copy link

@leileileidan You should create a pull request for this.

@YoussefHenna
Copy link

YoussefHenna commented May 12, 2022

mfcc = get_feature_vector_from_mfcc(filename, flatten=to_flatten)
mfcc = mfcc.reshape(mfcc.shape[0], mfcc.shape[1], 1)
print('prediction', model.predict_one(mfcc), 'Actual 3')

This fixed another issue for me where I was getting incorrect results for the final prediction. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants