Beispiel #1
0
    def augment(self, image, bboxes):
        image, bboxes = random_augmentations(image, self.augmentation_config, bboxes=bboxes)
        image, bboxes = random_function_bboxes(image, bboxes, random_pad_to_square, 0.3)

        # unfortunately we are still missing some augmentations in tf_image
        image = random_function(image, tf_py_contrast, prob=0.3)
        image = random_function(image, tf_py_blur, prob=0.3)
        image = random_function(image, tf_py_dropout, prob=0.3)

        return image, bboxes
Beispiel #2
0
    for o in soup.find_all("object"):
        xMin = int(o.find("xmin").string)
        yMin = int(o.find("ymin").string)
        xMax = int(o.find("xmax").string)
        yMax = int(o.find("ymax").string)
        bboxes.append([yMin, xMin, yMax, xMax])

    bboxes = np.array(bboxes, dtype=np.float32)

    # original bbox in relative coordinates [0...1]
    bboxes /= np.stack([h, w, h, w])

    for t in range(config.NUM_AUG):
        image_augmented, bboxes_augmented = random_augmentations(
            image,
            aug_config,
            bboxes=tf.constant(bboxes)
        )

        image_augmented_encoded = tf.image.encode_png(image_augmented)

        FILENAME_AUG = '{}_aug_{}.jpg'.format(filename, t)

        tf.io.write_file(os.path.sep.join([config.TRAIN_SET,
                                           FILENAME_AUG]),
                         image_augmented_encoded)

        # augmented bbox to absolute coordinates
        bboxes_abs = ((bboxes_augmented.numpy() *
                       np.stack([tf.shape(image_augmented)[0],
                                 tf.shape(image_augmented)[1],
Beispiel #3
0
 def augment(self, image, bboxes):
     return random_augmentations(image, self.augmentation_config, bboxes=bboxes)
Beispiel #4
0
image = tf.image.decode_jpeg(image_encoded)

bboxes = tf.constant([[262.0, 135.0, 504.0,
                       371.0], [285.0, 446.0, 494.0, 644.0],
                      [272.0, 688.0, 493.0, 895.0]])
bboxes /= tf.cast(
    tf.stack([
        tf.shape(image)[0],
        tf.shape(image)[1],
        tf.shape(image)[0],
        tf.shape(image)[1],
    ]), tf.float32)
bboxes_colors = [[0, 0, 255], [0, 0, 255], [0, 0, 255]]

for i in range(3):
    image_augmented = random_augmentations(image, config)

    image_augmented_encoded = tf.image.encode_png(image_augmented)
    tf.io.write_file(f"images/results/ximilar-similar_{i + 1}.png",
                     image_augmented_encoded)

for i in range(3):
    image_augmented, bboxes_augmented = random_augmentations(image,
                                                             config,
                                                             bboxes=bboxes)

    image_augmented = tf.image.draw_bounding_boxes([image_augmented],
                                                   [bboxes_augmented],
                                                   bboxes_colors)[0]
    image_augmented = tf.cast(
        image_augmented, tf.uint8