tf 版本更新 记录

tf 经常更新版本,网上教程又是各版本都有,且不标明版本,致使各种用法难以分清哪个新,哪个旧,这里做个记录,以前的博客我就不更新了,请大家见谅。

tf.nn.rnn_cell 改为 tf.contrib.rnn

# 原代码
lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(HIDDEN_SIZE)
if is_training:
    lstm_cell = tf.nn.rnn_cell.DropoutWrapper(lstm_cell, output_keep_prob=KEEP_PROB)
cell = tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * NUM_LAYERS)

# 修改为
lstm_cell = tf.contrib.rnn.BasicLSTMCell(HIDDEN_SIZE)
if is_training:
    lstm_cell = tf.contrib.rnn.DropoutWrapper(lstm_cell, output_keep_prob=KEEP_PROB)
cell = tf.contrib.rnn.MultiRNNCell([lstm_cell] * NUM_LAYERS)

tf.nn.seq2seq.sequence_loss_by_example 改为 tf.contrib.legacy_seq2seq.sequence_loss_by_example

# 原代码
loss = tf.nn.seq2seq.sequence_loss_by_example(
            [logits],  [tf.reshape(self.targets, [-1])], 
            [tf.ones([batch_size * num_steps], dtype=tf.float32)])

# 修改为
loss = tf.contrib.legacy_seq2seq.sequence_loss_by_example(
            [logits],  [tf.reshape(self.targets, [-1])], 
            [tf.ones([batch_size * num_steps], dtype=tf.float32)])

tf.concat

# 原代码
concated = tf.concat(1, [indices, labels])
# 修改为
concated = tf.concat([indices, labels], 1)
原文地址:https://www.cnblogs.com/yanshw/p/10550597.html