我目前正在尝试使用Waymo提供的开放数据集进行对象分类。我在尝试从提供的图像中裁剪出每个对象时遇到了一个问题。裁剪后,我想将“新的”较小图像添加到列表中,并将标签类型添加到对应对象的另一个列表中(x和y)。我的问题是,这些新裁剪的图像中有很多最终的宽度为= 0,这毫无意义...
这是代码的裁剪部分:
FILENAME = '/content/training/segment1.tfrecord'
dataset = tf.data.TFRecordDataset(FILENAME, compression_type='')
for data in dataset:
frame = open_dataset.Frame()
frame.ParseFromString(bytearray(data.numpy()))
break
x = []
y = []
def crop_and_append(camera_image, camera_labels):
for camera_labels in frame.camera_labels:
if camera_labels.name != camera_image.name:
continue
for label in camera_labels.labels:
img = tf.image.decode_jpeg(camera_image.image)
img_cropped = img[int(label.box.center_x - (0.5 * label.box.length)):int(label.box.center_x + (0.5 * label.box.length)),
int(label.box.center_y - (0.5 * label.box.width)):int(label.box.center_y + (0.5 * label.box.width))]
x.append(img_cropped)
y.append(label.type)
for index, image in enumerate(frame.images):
crop_and_append(image, frame.camera_labels, [3, 3, index+1])