speech_recognition icon indicating copy to clipboard operation
speech_recognition copied to clipboard

test.py文件报错

Open zhouhao-learning opened this issue 6 years ago • 1 comments

你好,我在运行您的test.py文件的时候,代码报错,不知道什么情况,这是我的测试代码:

wav_files = ['/home/zh/sda2/语音转文本/speech_recognition/data/test/D8/D8_999.wav']
txt_labels = ['国务委员 兼 国务院 秘书长 罗干 民政部 部长 多吉 才 让 也 一同 前往 延安 看望 人民群众']
words_size, words, word_num_map = utils.create_dict(txt_labels)
bi_rnn = BiRNN(wav_files, txt_labels, words_size, words, word_num_map)
bi_rnn.build_target_wav_file_test(wav_files, txt_labels)

配置文件:

[FILE_DATA]
wav_path=/opt/wav/test/
label_file=/home/zh/sda2/语音转文本/speech_recognition/model/test.word.txt
savedir=/home/zh/sda2/语音转文本/speech_recognition/model
savefile=speech.cpkt
tensorboardfile=/home/zh/sda2/语音转文本/speech_recognition/model

checkpoint文件内容:

model_checkpoint_path: "/home/zh/sda2/语音转文本/speech_recognition/model/speech.cpkt-101"
all_model_checkpoint_paths: "/home/zh/sda2/语音转文本/speech_recognition/model/speech.cpkt-101"

但是我得到这样的报错:

raceback (most recent call last):
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1322, in _do_call
    return fn(*args)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [36] rhsshape= [1788]
         [[Node: save/Assign_14 = Assign[T=DT_FLOAT, _class=["loc:@b6"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](b6/Adam_1, save/RestoreV2/_29)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    bi_rnn.build_target_wav_file_test(wav_files, txt_labels)
  File "/scratch2/hzhou/AI_voice/speech_recognition/model.py", line 344, in build_target_wav_file_test
    self.init_session()
  File "/scratch2/hzhou/AI_voice/speech_recognition/model.py", line 199, in init_session
    self.saver.restore(self.sess, ckpt)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1752, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run
    run_metadata_ptr)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1135, in _run
    feed_dict_tensor, options, run_metadata)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
    run_metadata)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [36] rhsshape= [1788]
         [[Node: save/Assign_14 = Assign[T=DT_FLOAT, _class=["loc:@b6"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](b6/Adam_1, save/RestoreV2/_29)]]

Caused by op 'save/Assign_14', defined at:
  File "test.py", line 24, in <module>
    bi_rnn.build_target_wav_file_test(wav_files, txt_labels)
  File "/scratch2/hzhou/AI_voice/speech_recognition/model.py", line 344, in build_target_wav_file_test
    self.init_session()
  File "/scratch2/hzhou/AI_voice/speech_recognition/model.py", line 186, in init_session
    self.saver = tf.train.Saver(max_to_keep=1)  # 生成saver
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1284, in __init__
    self.build()
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1296, in build
    self._build(self._filename, build_save=True, build_restore=True)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1333, in _build
    build_save=build_save, build_restore=build_restore)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 781, in _build_internal
    restore_sequentially, reshape)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 422, in _AddRestoreOps
    assign_ops.append(saveable.restore(saveable_tensors, shapes))
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 113, in restore
    self.op.get_shape().is_fully_defined())
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/ops/state_ops.py", line 219, in assign
    validate_shape=validate_shape)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign
    use_locking=use_locking, name=name)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3414, in create_op
    op_def=op_def)
  File "/atlas/home/hzhou/.local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1740, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [36] rhs shape= [1788]
         [[Node: save/Assign_14 = Assign[T=DT_FLOAT, _class=["loc:@b6"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](b6/Adam_1, save/RestoreV2/_29)]]

请问是您提供的模型有问题还是别的原因呢?请给我一些指导,谢谢

zhouhao-learning avatar Jul 15 '19 13:07 zhouhao-learning

我运行了test.py里面的bi_rnn.build_test()函数,你提供的模型能够正常预测,但是我想要输入一个自己的wav文件进行预测,所以你能提供给我一个可以用的模型吗

zhouhao-learning avatar Jul 15 '19 14:07 zhouhao-learning