tf.train.batch和tf.train.shuffle_batch理解以及遇到的问题

函数原型
  tf.train.batch([example, label], batch_size=batch_size, capacity=capacity)

1. [example, label]表示样本和样本标签,这个可以是一个样本和一个样本标签
2. batch_size是返回的一个batch样本集的样本个数。
3. capacity是队列中的容量。这主要是按顺序组合成一个batch

  tf.train.shuffle_batch([example, label], batch_size=batch_size, capacity=capacity)

  里面的参数和上面的一样的意思。不一样的是这个参数min_after_dequeue。
min_after_dequeue。一定要保证这参数小于capacity参数的值,否则会出错。
  这个代表队列中的元素大于它的时候就输出乱的顺序的batch。也就是说这个函数的输出结果是一个乱序的样本排列的batch,不是按照顺序排列的。

  上面的函数返回值都是一个batch的样本和样本标签,只是一个是按照顺序,另外一个是随机的

  遇到的错误

ValueError: All shapes must be fully defined: [TensorShape([Dimension(32), Dimension(32), Dimension(None)]), TensorShape([])]

解决方法:

The batching methods in TensorFlow (tf.train.batch(), tf.train.batch_join(), tf.train.shuffle_batch(), and tf.train.shuffle_batch_join()) require that every element of the batch has the exact same shape*, so that they can be packed into dense tensors. In your code, it appears that the third dimension of the image tensor that you pass to tf.train.shuffle_batch() has unknown size. This corresponds to the number of channels in each image, which is 1 for monochrome images, 3 for color images, or 4 for color images with an alpha channel. If you pass an explicit channels=N (where N is 1, 3, or 4 as appropriate), this will give TensorFlow enough information about the shape of the image tensor to proceed.

以上说明在调用tf.train.shuffle_batch前要指定读取数据的大小,可调用

images = tf.image.resize_images(images, new_size)来实现

需要注意的是:new_size是一个int32的tensor
eg .new_size = tf.constant([48*4, 48], dtype=tf.int32)

参考网址:
tf.image.resize_images

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值