我正在为每个元素构建一个具有两个形状 [batch,width,height,3] 和 [batch,class] 的张量的数据集。为了简单起见,我们假设 class = 5。
你吃什么形状的dataset.padded_batch(1000,shape)
这样图像沿着宽度/高度/3 轴填充?
我已经尝试过以下方法:
tf.TensorShape([[None,None,None,3],[None,5]])
[tf.TensorShape([None,None,None,3]),tf.TensorShape([None,5])]
[[None,None,None,3],[None,5]]
([None,None,None,3],[None,5])
(tf.TensorShape([None,None,None,3]),tf.TensorShape([None,5]))
每次都会引发 TypeError
The docs https://www.tensorflow.org/versions/master/api_docs/python/tf/data/Dataset#padded_batch state:
padded_shapes:tf.TensorShape 或 tf.int64 向量的嵌套结构
类似张量的对象,表示各自的形状
应在批处理之前填充每个输入元素的组件。
任何未知维度(例如 tf.TensorShape 中的 tf.Dimension(None) 或
-1(在类似张量的对象中)将在每个批次中填充到该维度的最大大小。
相关代码:
dataset = tf.data.Dataset.from_generator(generator,tf.float32)
shapes = (tf.TensorShape([None,None,None,3]),tf.TensorShape([None,5]))
batch = dataset.padded_batch(1,shapes)