反思tensorflow实现RNN中遇到的问题

  1. 在写placeholder时,shape参数一定要和喂给的数据shape一致,这是毋庸置疑的。

    x = tf.placeholder(tf.float32, shape=[None, 71], name='x_input')
    y_ = tf.placeholder(tf.float32, shape=[None, 1], name='y_input')
    
  2. tensorflow在运行过程中,遇到某变量存在于feed_dict中时,就会直接把feed_dict喂给程序

    x = tf.placeholder(tf.float32, shape=[None, 71], name='x_input')
    x_re = tf.reshape(x, [-1, 1, 71]) #起初用  x = tf.reshape(x, [-1, 1, 71]) 
    
    #下行中的inputs=x_re起初写做x
    outputs, date = tf.nn.dynamic_rnn(mlstm_cell, inputs=x_re, initial_state=init_state, time_major=False)
    
    #运行train_step,tensorflow在往上寻到inputs=x一句时,直接把feed_dict喂进来了,于是提示shape不匹配
    feed_dict = {x: x_date_batch, y_: y_data_batch, keep_prob: 1.0}
     _, loss_value, y_value, y__value = sess.run((train_step, loss, y, y_), feed_dict=feed_dict)
    

你可能感兴趣的:(反思tensorflow实现RNN中遇到的问题)