替换tensorflow 1.0+中的tf.contrib.learn.run_n

时间:2017-06-07 16:47:13

标签: python tensorflow

我使用tensorflow 1.1.0来运行用先前版本的tensorflow编写的代码。它包括这一部分:

cell = tf.contrib.rnn.LSTMCell(num_units=64, state_is_tuple=True)

outputs, last_states = tf.nn.dynamic_rnn(
    cell=cell,
    dtype=tf.float64,
    sequence_length=X_lengths,
    inputs=X)

result = tf.contrib.learn.run_n(
    {"outputs": outputs, "last_states": last_states},
    n=1,
    feed_dict=None)

我收到以下警告:

WARNING:tensorflow:From tensorflow/contrib/learn/python/learn/graph_actions.py:900: run_feeds_iter (from tensorflow.contrib.learn.python.learn.graph_actions) is deprecated and will be removed after 2017-02-15.
Instructions for updating:
graph_actions.py will be deleted. Use tf.train.* utilities instead. You can use learn/estimators/estimator.py as an example.

我在tensroflow 1.0+中找不到tf.contrib.learn.run_n的替换。我可以使用替代功能吗?

1 个答案:

答案 0 :(得分:1)

我不确定是否有一个函数可以直接替换有问题的函数。以下备选方案应该在没有警告的情况下运行:

n_iter = 1
result = []
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for i in range(n_iter):
        result_ = sess.run({'outputs': outputs, 'last_states':last_states}, feed_dict=None)
        result.append(result_)