astorfi / 3D-convolutional-speaker-recognition

:speaker: Deep Learning & 3D Convolutional Neural Networks for Speaker Verification
Apache License 2.0
778 stars 275 forks source link

ValueError: axes don't match array #47

Closed MSAlghamdi closed 5 years ago

MSAlghamdi commented 5 years ago

To make multiple models from multiple wav files, I added the following to the input_features.py in order to generate .hdf5 file for all wav files I have:

idx = 0
f = open('file_path_test1.txt','r')
for line in f:
idx = idx + 1

lab = []
feat = []
for i in range(idx):
    feature, label = dataset.__getitem__(i)
    lab.append(label)
    feat.append(feature)
    print(feature.shape) 
    print(label) 
######################
## creating hdf5 file ##
######################
h5file = tables.open_file('/root/3D_CNN/3D-convolutional-speaker-recognition/data/evaluation_test.hdf5', 'w')
label_test = h5file.create_carray(where = '/', name = 'label_enrollment', obj = lab, byteorder = 'little')
label_array = h5file.create_carray(where = '/', name = 'label_evaluation', obj = lab, byteorder = 'little')
utterance_test = h5file.create_earray(where = '/', name = 'utterance_enrollment', chunkshape = [1,20,80,40], obj = feat, byteorder = 'little')
utterance_train = h5file.create_earray(where = '/', name = 'utterance_evaluation', `chunkshape = [1,20,80,40]`, obj = feat, byteorder = 'little')
n5file.close()`

When I ran input_features.py, it gave me the following error: ValueError: the shape ((0, 1, 20, 80, 40)) and chunkshape ((1, 20, 80, 40)) ranks must be equal. I recognized that lab and feat are arrays and each one has 9 elements (# of wav files I want to test). Each element of the feat array has the features of each wav file in my wav list. So what I did is changing chunkshape values to be chunkshape = [9,1,20,80,40] and the evaluation_test.hdf5 file was created with no errors.

When I used hdf5 file that I created to run run.sh I got this:


Train data shape: (12, 80, 40, 20)
Train label shape: (12,)
Test data shape: (12, 80, 40, 20)
Test label shape: (12,)
Epoch 1, Minibatch 1 of 4 , Minibatch Loss= 0.0000, TRAIN ACCURACY= 100.000
Epoch 1, Minibatch 2 of 4 , Minibatch Loss= 1.2341, TRAIN ACCURACY= 100.000
Epoch 1, Minibatch 3 of 4 , Minibatch Loss= 1.4641, TRAIN ACCURACY= 0.000
Epoch 1, Minibatch 4 of 4 , Minibatch Loss= 1.4434, TRAIN ACCURACY= 0.000
TESTING after finishing the training on: epoch 1
Test Accuracy 1, Mean= 50.0000, std= 50.000
Closing remaining open files:data/development_sample_dataset_speaker.hdf5...done
Enrollment data shape: (9, 1, 20, 80, 40)
Enrollment label shape: (9,)
Evaluation data shape: (9, 1, 20, 80, 40)
Evaluation label shape: (9,)
INFO:tensorflow:Scale of 0 disables regularizer.
.
.
Traceback (most recent call last):
  File "./code/2-enrollment/enrollment.py", line 330, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "./code/2-enrollment/enrollment.py", line 289, in main
    assert len(speaker_index) >= NumUtterance, "At least %d utterances is needed for each speaker" % NumUtterance
AssertionError: At least 20 utterances is needed for each speaker
Closing remaining open files:data/development_sample_dataset_speaker.hdf5...donedata/eval_try.hdf5...done
Enrollment data shape: (9, 1, 20, 80, 40)
Enrollment label shape: (9,)
Evaluation data shape: (9, 1, 20, 80, 40)
Evaluation label shape: (9,)
INFO:tensorflow:Scale of 0 disables regularizer.
.
.
Traceback (most recent call last):
  File "./code/3-evaluation/evaluation.py", line 380, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "./code/3-evaluation/evaluation.py", line 329, in main
    speech_evaluation = np.transpose(speech_evaluation[None, :, :, :, :], axes=(1, 4, 2, 3, 0))
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 598, in transpose
    return _wrapfunc(a, 'transpose', axes)
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 51, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
ValueError: axes don't match array
Closing remaining open files:data/development_sample_dataset_speaker.hdf5...donedata/eval_try.hdf5...done
('EER=', 43.75, 0.0)
('AUC=', 48.4375, 0.0)
('EER = ', 0.44)
('AUC = ', 0.48)
('AP = ', 0.33)

I'm not sure how to fix this: ValueError: axes don't match array