gpt4 book ai didi

python - tf.global_variables_initializer() 还会初始化 tf.data.Dataset 的迭代器吗?

转载 作者:行者123 更新时间:2023-11-30 22:10:10 25 4
gpt4 key购买 nike

我想知道tf.global_variables_initializer()是否也初始化tf.data.Datasetiterator,或者我需要初始化迭代器分别为:


迭代器 = dataset.make_initialized_iterator()
sess.run(迭代器.初始化器)

最佳答案

您必须单独初始化迭代器。tf.global_variables_initializer()

没有 变量提要

official example :

max_value = tf.placeholder(tf.int64, shape=[])
dataset = tf.data.Dataset.range(max_value)
iterator = dataset.make_initializable_iterator()
next_element = iterator.get_next()

# Initialize an iterator over a dataset with 10 elements.
sess.run(iterator.initializer, feed_dict={max_value: 10})
for i in range(10):
value = sess.run(next_element)
assert i == value

# Initialize the same iterator over a dataset with 100 elements.
sess.run(iterator.initializer, feed_dict={max_value: 100})
for i in range(100):
value = sess.run(next_element)
assert i == value

关于python - tf.global_variables_initializer() 还会初始化 tf.data.Dataset 的迭代器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51736628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com