我正在尝试将小批量的 numpy 数组提供给我的模型,但我坚持使用批处理。使用 'tf.train.shuffle_batch' 会引发错误,因为 'images' 数组大于 2 GB。我试图绕过它并创建占位符,但是当我尝试提供数组时,它们仍然由 tf.Tensor 对象表示。我主要担心的是我在模型类下定义了操作,并且在运行会话之前不会调用对象。有谁知道如何处理这个问题?
def main(mode, steps):
config = Configuration(mode, steps)
if config.TRAIN_MODE:
images, labels = read_data(config.simID)
assert images.shape[0] == labels.shape[0]
images_placeholder = tf.placeholder(images.dtype,
images.shape)
labels_placeholder = tf.placeholder(labels.dtype,
labels.shape)
dataset = tf.data.Dataset.from_tensor_slices(
(images_placeholder, labels_placeholder))
# shuffle
dataset = dataset.shuffle(buffer_size=1000)
# batch
dataset = dataset.batch(batch_size=config.batch_size)
iterator = dataset.make_initializable_iterator()
image, label = iterator.get_next()
model = Model(config, image, label)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(iterator.initializer,
feed_dict={images_placeholder: images,
labels_placeholder: labels})
# ...
for step in xrange(steps):
sess.run(model.optimize)