从 Tensorflow 中的自定义图像数据集创建批次
Creating batches from custom dataset of images in Tensorflow
我正在从磁盘读取 .jpg 图像列表,我想将其分成几批。但是我在尝试创建第一批时遇到了 ValueError。
这是我的代码:
import tensorflow as tf
import os
images_list = []
for i in range(6):
image = tf.read_file("{0}.jpg".format(i))
image_tensor = tf.image.decode_jpeg(image, channels=3)
image_tensor = tf.image.rgb_to_grayscale(image_tensor)
image_tensor = tf.image.resize_images(image_tensor, 28, 28)
image_tensor = tf.expand_dims(image_tensor, 0)
images_list.append(image_tensor)
batches, _ = tf.train.batch(images_list, batch_size=3, enqueue_many=True, capacity=6)
这是错误信息:
ValueError Traceback (most recent call last)
<ipython-input-77-a07e94cddf32> in <module>()
----> 1 batches, _ = tf.train.batch(images_list, batch_size=3, enqueue_many=True, capacity=6)
ValueError: too many values to unpack
您的错误消息根本没有链接到 TensorFlow(您可以看到 ValueError 不是 TensorFlow 抛出的)。
如果您查看 doc,您会看到 tf.train.batch()
returns 一个张量列表(总共一个值),并且您试图在以下情况下获取两个值你写 batches, _ = tf.train.batch(...)
.
这就是为什么你得到 ValueError: too many values to unpack
。
您只需改为:
batches = tf.train.batch(images_list, batch_size=3, enqueue_many=True, capacity=6)
我正在从磁盘读取 .jpg 图像列表,我想将其分成几批。但是我在尝试创建第一批时遇到了 ValueError。
这是我的代码:
import tensorflow as tf
import os
images_list = []
for i in range(6):
image = tf.read_file("{0}.jpg".format(i))
image_tensor = tf.image.decode_jpeg(image, channels=3)
image_tensor = tf.image.rgb_to_grayscale(image_tensor)
image_tensor = tf.image.resize_images(image_tensor, 28, 28)
image_tensor = tf.expand_dims(image_tensor, 0)
images_list.append(image_tensor)
batches, _ = tf.train.batch(images_list, batch_size=3, enqueue_many=True, capacity=6)
这是错误信息:
ValueError Traceback (most recent call last)
<ipython-input-77-a07e94cddf32> in <module>()
----> 1 batches, _ = tf.train.batch(images_list, batch_size=3, enqueue_many=True, capacity=6)
ValueError: too many values to unpack
您的错误消息根本没有链接到 TensorFlow(您可以看到 ValueError 不是 TensorFlow 抛出的)。
如果您查看 doc,您会看到 tf.train.batch()
returns 一个张量列表(总共一个值),并且您试图在以下情况下获取两个值你写 batches, _ = tf.train.batch(...)
.
这就是为什么你得到 ValueError: too many values to unpack
。
您只需改为:
batches = tf.train.batch(images_list, batch_size=3, enqueue_many=True, capacity=6)