1 回答
TA贡献1946条经验 获得超4个赞
dataset.batch(16)更改为 后该错误将得到解决dataset.padded_batch(16)。
下面是相同的修改后的代码。
import tensorflow as tf
@tf.function()
def prepare_sample(annotation):
annotation_parts = tf.strings.split(annotation, sep=' ')
image_file_name = annotation_parts[0]
image_file_path = tf.strings.join(["/images/", image_file_name])
depth_image = tf.io.read_file(image_file_path)
bboxes = tf.reshape(annotation_parts[1:], shape=[-1,4])
return depth_image, bboxes
annotations = ['image1.png 1 2 3 4', 'image2.png 1 2 3 4 5 6 7 8']
dataset = tf.data.Dataset.from_tensor_slices(annotations)
dataset = dataset.shuffle(len(annotations))
dataset = dataset.map(prepare_sample)
dataset = dataset.padded_batch(16)
for image, bboxes in dataset:
pass
添加回答
举报