无法将张量添加到批处理中:元素数量不匹配。形状为:[张量]:[5],[批处理]:[3]

时间:2020-07-10 06:26:58

标签: python tensorflow deep-learning tensorflow2.0 tensorflow-datasets

Tensorflow 2.2-gpu <br/>
pycharm 

当我将batch_size选项1更改为它提供的任何数字时

tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [5], [batch]: [3]

原始代码没有什么特别的

def train():
    print('train')
    if isprint:print(tf.__version__)
    batch_size= 2
    images,boxes,labels,difficulties,new_boxes= PascalVOCDataset()
    new_boxes = list(new_boxes)
    boxes = tf.ragged.constant(boxes)
    labels = tf.ragged.constant(labels)
    new_boxes = tf.ragged.constant(new_boxes)
    dataset = tf.data.Dataset.from_tensor_slices((images,new_boxes,labels))
    run_train(dataset.map(resize_image_bbox, num_parallel_calls=tf.data.experimental.AUTOTUNE).batch(batch_size).prefetch(tf.data.experimental.AUTOTUNE))

image_shape-> (2, 300, 300, 3)
labels_shape-> (2, 2)
boxes_shape-> (2,)

0 个答案:

没有答案