如何在imgaug中使用多个边界框进行批处理。

问题描述 投票:0回答:0

我正试图建立一个数据增强管道,与 IMGUG. 图像的转换工作正常,没有出现任何错误。在第二次尝试中,我试图为每个图像转换N个Bounding Boxes,但我得到一个持续的错误。

def image_batch_augmentation(batch_images, batch_bbox, batch_image_shape):

    def create_BoundingBox(bbox):
        return BoundingBox(bbox[0], bbox[1], bbox[2], bbox[3], bbox[4])

    bbox = [[create_BoundingBox(bbox) for bbox in batch if sum(bbox) != 0]for batch in batch_bbox]

    bbox = [BoundingBoxesOnImage(batch, shape=(h,w)) for batch, w, h in zip(bbox,batch_image_shape[0], batch_image_shape[1]) ]

    seq_det = seq.to_deterministic()
    aug_image = seq_det.augment_images(image.numpy())
    aug_bbox = [seq_det.augment_bounding_boxes(batch) for batch in bbox]

    return aug_image, aug_bbox

在下面的行中出现了以下错误:aug_bbox = seq_det.augment_bounding_boxes(bbox)

Exception has occurred: InvalidArgumentError
cannot compute Mul as input #1(zero-based) was expected to be a double tensor but is a int64 tensor [Op:Mul] name: mul/

我已经尝试了几种不同的方法,但我无法取得任何进展。此外,我在文档或其他已知的平台中没有找到任何信息可以帮助我让代码运行。

image-processing data-processing data-augmentation module-augmentation
0
投票

从数据类型上的错误信息可以看出,问题不断。对这些进行调整后,获得了成功。

下面是实际运行的相应代码。

def image_batch_augmentation(batch_images, batch_bbox, batch_image_shape):

    def create_BoundingBox(bbox, w, h):
        return BoundingBox(bbox[0]*h, bbox[1]*w, bbox[2]*h, bbox[3]*w, tf.cast(bbox[4], tf.int32))



    bbox = [[create_BoundingBox(bbox, float(w), float(h)) for bbox in batch if sum(bbox) != 0] for batch, w, h in zip(batch_bbox, batch_image_shape[0], batch_image_shape[1])]

    bbox = [BoundingBoxesOnImage(batch, shape=(int(w),int(h))) for batch, w, h in zip(bbox,batch_image_shape[0], batch_image_shape[1]) ]

    seq_det = seq.to_deterministic()
    images_aug = seq_det.augment_images(image.numpy())
    bbsoi_aug = seq_det.augment_bounding_boxes(bbox)

    return images_aug, bbsoi_aug
© www.soinside.com 2019 - 2024. All rights reserved.