我使用的是Tensorflow 1.0和它的CTC丢失1。在训练时,我有时会得到“没有找到有效的路径”。警告(对学习有害)。它是,而不是,因为其他Tensorflow用户有时会报告它的高学习率。
在对其进行了一些分析之后,我发现了导致此警告的模式:
三个例子:
当我现在设置ctc_loss参数ctc_merge_repeated=False时,警告将消失。
三个问题:
用于复制警告的Python程序:
import tensorflow as tf
import numpy as np
def createGraph():
tinputs=tf.placeholder(tf.float32, [100, 1, 65]) # max 100 time steps, 1 batch element, 64+1 classes
tlabels=tf.SparseTensor(tf.placeholder(tf.int64, shape=[None,2]) , tf.placeholder(tf.int32,[None]), tf.placeholder(tf.int64,[2])) # labels
tseqLen=tf.placeholder(tf.int32, [None]) # list of sequence length in batch
tloss=tf.reduce_mean(tf.nn.ctc_loss(labels=tlabels, inputs=tinputs, sequence_length=tseqLen, ctc_merge_repeated=True)) # ctc loss
return (tinputs, tlabels, tseqLen, tloss)
def getNextBatch(nc): # next batch with given number of chars in label
indices=[[0,i] for i in range(nc)]
values=[i%65 for i in range(nc)]
values[0]=0
values[1]=0 # TODO: (un)comment this to trigger warning
shape=[1, nc]
labels=tf.SparseTensorValue(indices, values, shape)
seqLen=[nc]
inputs=np.random.rand(100, 1, 65)
return (labels, inputs, seqLen)
(tinputs, tlabels, tseqLen, tloss)=createGraph()
sess=tf.Session()
sess.run(tf.global_variables_initializer())
nc=3 # number of chars in label
print('next batch with 1 element has label len='+str(nc))
(labels, inputs, seqLen)=getNextBatch(nc)
res=sess.run([tloss], { tlabels: labels, tinputs:inputs, tseqLen:seqLen } )这是来自C++ Tensorflow代码2的警告:
// It is possible that no valid path is found if the activations for the
// targets are zero.
if (log_p_z_x == kLogZero) {
LOG(WARNING) << "No valid path found.";
dy_b = y;
return;
}发布于 2017-10-02 23:29:17
好的,明白了,这不是一个bug,这就是CTC的工作方式:让我们举一个警告发生的例子:输入序列的长度是2,标签是"aa“(也就是长度2)。
现在产生"aa“的最短路径是a->空白->a(长度3)。但对于标签"ab",最短路径是a->b (长度2)。这说明了为什么像"aa“中的重复标签的输入序列必须更长。这只是通过插入空格在CTC中编码重复标签的方式。
因此,当确定输入大小时,标签重复次数会减少允许的标签的最大长度。
https://stackoverflow.com/questions/45568266
复制相似问题