我是TensorFlow的新手 . 我正在尝试 Build 一个网络来分类不同类型的时序波数据 .

我的基本想法是使用LSTM顺序学习波的采样点 . 输入大小为1,波长是可变的,填充到数据集的最大长度 . “sequence_length”在“dynamic_rnn”中设置以掩盖真实长度 .

然而, the output of my model does not change after the first several steps. All the predictions are nearly the same for each training sample. 似乎网络没有学习 . 我无法弄清楚我的模型出了什么问题 .

以下是简要代码 . 波长从3k到20k不等 . n_hidden_units设置为16,batch_size为16,n_inputs为1,n_classes为3,lr(学习率)为0.01 .

xs = tf.placeholder(tf.float64, [batch_size, len_max, n_inputs],  name='sample')
ys = tf.placeholder(tf.float64, [batch_size, n_classes], name='label')
lens_ph = tf.placeholder(tf.int32,[batch_size],name='lens_in_batch') 

cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden_units,forget_bias=0.9)
output, state = tf.nn.dynamic_rnn(cell, xs, time_major=False, dtype=tf.float64, initial_state=None,sequence_length=lens_ph)
last = last_relevant(output, lens_ph)
output_final = tf.layers.dense(last, n_classes,activation=None)
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=ys, logits=tf.clip_by_value(output_final,1e-10,1.0))
loss_scalar = tf.reduce_mean(cross_entropy)
optimizer = tf.train.AdamOptimizer(lr).minimize(cross_entropy)

with tf.Session() as sess:
    init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
    sess.run(init_op)
    for step in range(n_epochs):
        X,y,lens_in_batch = get_batch(train_data, train_label, lens_in_train)
        X = np.reshape(X,(batch_size,len_max,n_inputs))

        _ = sess.run(optimizer,{xs: X, ys: y, lens_ph:lens_in_batch})

        if step % n_epochs_print == 0:
            output_final_,loss_ = sess.run([output_final,loss_scalar], {xs: X, ys: y, lens_ph:lens_in_batch})
            print('output: ', output_final_)
            print('predict label: ', np.argmax(output_final_, 1))
            print('actual label : ', np.argmax(y, 1))
            print('train loss: %.4f' % loss_)