你需要使用 reuse 选项正确。以下更改将解决它。对于预测,您需要使用图中已存在的变量。
reuse
def RNN(inputs, reuse): with tf.variable_scope('cells', reuse=reuse): basic_cell = tf.contrib.rnn.BasicRNNCell(num_units=batch_size, reuse=reuse) ... ... #Training cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=train_label_batch, logits=RNN(train_batch, reuse=None))) #Accuracy ... correct_prediction = tf.equal(tf.argmax(RNN(test_image, reuse=True), 1), tf.argmax(test_image_label, 0))