speech_recognition
speech_recognition copied to clipboard
cpu跑build_target_wav_file_test报InvalidArgumentError
修改了代码中使用gpu的部分。 两处地方:
# with tf.device('/gpu:0'):
with tf.device('/cpu:0'):
# gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7)
# self.sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
self.sess = tf.Session()
修改完之后报错: InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [36] rhs shape= [1788]
我同样遇到了这种错误,上网查说是restore的时候ckpt越界了,但是实际上我并没有发现越界啊。
是我上传的模型问题?
恩,是的,直接就报错了,运行测试代码的时候,就报这个错误
def init_session(self):
self.savedir = self.conf.get("FILE_DATA").savedir
self.saver = tf.train.Saver(max_to_keep=1) # 生成saver
# create the session
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7)
self.sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
# sess = tf.Session()
# 没有模型的话,就重新初始化
self.sess.run(tf.global_variables_initializer())
ckpt = tf.train.latest_checkpoint(self.savedir)
print("ckpt:", ckpt)
self.startepo = 0
if ckpt != None:
self.saver.restore(self.sess, ckpt)
ind = ckpt.rfind("-")
self.startepo = int(ckpt[ind + 1:])
print(self.startepo)
print()
就上面这段代码中self.saver.restore(self.sess, ckpt)这句话一运行就报错:InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [36] rhs shape= [1788]
我是运行完成了120次之后的,您是运行到100次就手动停止了吗
我是kill进程停止的,我是用gpu训练的,和你用cpu训练有关系吗?
没有,我也是用GPU训练的,然后训练完事直接用GPU测试的 ,测试的是用 wav_files = ['D:\音频相似度文档\声音相关的模型\Chinese-speech-to-text-master\A11_1.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)
用的是这个,没用上面测试的训练方法
我第二次重新训练,训练了两步结束kill掉,也是不行,报同样的错误,上网查说是张量错误,您运行测试代码的时候是没有问题的吗
用您这个链接中:https://pan.baidu.com/s/1skGXz8x#list/path=%2F。 提供训练好的模型,然后去测试报同样的错误。所以,您看看是不是您test中的调用应该修改什么东西啊?谢谢了
我没改什么,那你自己训练一个新模型试试呢?
我也是遇到一样的问题,你现在解决了么?还有你自己训练好的模型好用么? @feifaxiaoming
@crazygirl1992 自己训练的模型也是可以的,但是你测试的时候,训练的模型是什么样的,就得用什么测试,因为作者提供的代码那里面的张量是根据训练时候的文字数量去定的,固定死了,所以你只要换成子的就报错了。
@你使用build_target_wav_file_test报InvalidArgumentError,是因为bi_rnn.build_target_wav_file_test(wav_files, txt_labels) 这个wav_files变量有问题,它是所有训练的WAV文件,你要改成自己的测试wav,单独命名就好了
@feifaxiaoming
@soulspirit1229 你成功了吗,我也是用的CPU同样的问题啊
Assign requires shapes of both tensors to match. lhs shape= [512,14] rhs shape= [512,1788] [[node save/Assign_41 (defined at /home/junli/Downloads/speech_recognition-master/model.py:186) = Assign[T=DT_FLOAT, _class=["loc:@h6"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](h6/Adam_1, save/RestoreV2:41)]]
Assign requires shapes of both tensors to match. lhs shape= [512,14] rhs shape= [512,1788] [[node save/Assign_41 (defined at /home/junli/Downloads/speech_recognition-master/model.py:186) = Assign[T=DT_FLOAT, _class=["loc:@H6"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](h6/Adam_1, save/RestoreV2:41)]]
我也是直接用test.py训练D*字头的测试集报这个错, 感觉这个:hs shape= [512,14] rhs shape= [512,1788]应该是在恢复的时候,新测试数据中1788和原来训练集字表大小不一致,restore时出错的.还不知道怎么改.
请问你们是怎么使用CPU运行的,我按照楼主的方法改成CPU,但CPU根本跑不起来,报错:
Traceback (most recent call last):
File "tf_speech.py", line 27, in <module>
re = X.speech_to_text('./test_voice/D4_750.wav')
File "tf_speech.py", line 22, in speech_to_text
res = bi_rnn.build_target_wav_file_test(wav_files, self.text_labels)
File "/home/zh/sda2/sg-ai/Detox_AI/tf_recong/model.py", line 214, in build_target_wav_file_test
self.init_session()
File "/home/zh/sda2/sg-ai/Detox_AI/tf_recong/model.py", line 185, in init_session
ckpt = tf.train.latest_checkpoint(self.savedir)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1805, in latest_checkpoint
ckpt = get_checkpoint_state(checkpoint_dir, latest_filename)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1061, in get_checkpoint_state
text_format.Merge(file_content, ckpt)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 536, in Merge
descriptor_pool=descriptor_pool)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 590, in MergeLines
return parser.MergeLines(lines, message)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 623, in MergeLines
self._ParseOrMerge(lines, message)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 638, in _ParseOrMerge
self._MergeField(tokenizer, message)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 763, in _MergeField
merger(tokenizer, message, field)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 888, in _MergeScalarField
value = tokenizer.ConsumeString()
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 1251, in ConsumeString
the_bytes = self.ConsumeByteString()
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 1266, in ConsumeByteString
the_list = [self._ConsumeSingleByteString()]
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_format.py", line 1291, in _ConsumeSingleByteString
result = text_encoding.CUnescape(text[1:-1])
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_encoding.py", line 103, in CUnescape
result = ''.join(_cescape_highbit_to_str[ord(c)] for c in result)
File "/home/zh/sda3/Anaconda3/envs/deep2.0.0/lib/python3.6/site-packages/google/protobuf/text_encoding.py", line 103, in <genexpr>
result = ''.join(_cescape_highbit_to_str[ord(c)] for c in result)
IndexError: list index out of range