warpctc函数计算loss一直为0的问题
Created by: guyinyou
1)PaddlePaddle版本:1.6.2(1.70也试过) 3)GPU:无 4)系统环境:Python3.7,AI Studio 在线 notebook 环境
问题如下: 首先随机x作为ctc的输出,然后随机y1,y2作为标签 其中y1后10位置0来模拟真实场景,y2不做处理 最后用warpctc计算loss得到下图(y1一直为0,y2有值):
以下是具体代码 `import paddle as paddle import paddle.fluid as fluid import numpy as np import paddle.fluid as fluid import numpy as np
batch_size = 1 max_seq_length = 30 num_classes = 64 place = fluid.CPUPlace() if name == 'main': with fluid.dygraph.guard(place): x = fluid.dygraph.to_variable(np.random.rand(max_seq_length, batch_size, num_classes + 1).astype('float32')) y = np.random.randint(0, num_classes, [batch_size, max_seq_length]).astype('int32') for i in range(max_seq_length-20): y[0,i+20] = 0 y = fluid.dygraph.to_variable(y)#模拟真实标签 y2 = np.random.randint(0, num_classes, [batch_size, max_seq_length]).astype('int32') y2 = fluid.dygraph.to_variable(y2)#随机标签 x_len = fluid.dygraph.to_variable(np.array([max_seq_length] * batch_size).astype('int64')) y_len = fluid.dygraph.to_variable(np.array([max_seq_length] * batch_size).astype('int64')) cost = fluid.layers.warpctc(input=x, label=y, blank=0, input_length=x_len, label_length=y_len,norm_by_times=True) print("————————————————————————Simulate real Tags————————————————————") print(y.numpy()) print(cost) cost2 = fluid.layers.warpctc(input=x, label=y2, blank=0, input_length=x_len, label_length=y_len,norm_by_times=True) print("————————————————————————Random Tags————————————————————") print(y2.numpy()) print(cost2)`