我正在使用TensorFlow版本:0.11.0rc0并将代码转换为该版本,以便可以在我的AMD GPU上运行。我很难阅读旧文档,因为多年来tensorflow似乎发生了很大变化。任何见解都将对reverse()函数有所帮助,并希望如何对其进行更改以使其起作用。
这是我要转换为.11的网络的代码,但据我了解,反向功能现在以不同的方式起作用:
# Build the graph
train_graph = tf.Graph()
# Set the graph to default to ensure that it is ready for training
with train_graph.as_default():
# Load the model inputs
input_data, targets, lr, keep_prob, summary_length, max_summary_length, text_length = model_inputs()
# Create the training and inference logits
training_logits, inference_logits = seq2seq_model(tf.reverse(input_data,[-1]),
targets,
keep_prob,
text_length,
summary_length,
max_summary_length,
len(vocab_to_int)+1,
rnn_size,
num_layers,
vocab_to_int,
batch_size
)
# Create tensors for the training logits and inference logits
training_logits = tf.identity(training_logits[0].rnn_output, 'logits')
inference_logits = tf.identity(inference_logits[0].sample_id, name='predictions')
# Create the weights for sequence_loss, the sould be all True across since each batch is padded
masks = tf.sequence_mask(summary_length, max_summary_length, dtype=tf.float32, name='masks')
with tf.name_scope("optimization"):
# Loss function
cost = tf.contrib.seq2seq.sequence_loss(
training_logits,
targets,
masks)
# Optimizer
optimizer = tf.train.AdamOptimizer(learning_rate)
# Gradient Clipping
gradients = optimizer.compute_gradients(cost)
capped_gradients = [(tf.clip_by_value(grad, -5., 5.), var) for grad, var in gradients if grad is not None]
train_op = optimizer.apply_gradients(capped_gradients)
print("Graph is built.")
graph_location = "./graph"
print(graph_location)
train_writer = tf.summary.FileWriter(graph_location)
train_writer.add_graph(train_graph)