示例#1
0
    def _load_batches(cls, load_batch_func, queue_internal, join_signal,
                      seedval):
        if seedval is not None:
            random.seed(seedval)
            np.random.seed(seedval)
            iarandom.seed(seedval)

        try:
            gen = (load_batch_func() if not ia.is_generator(load_batch_func)
                   else load_batch_func)
            for batch in gen:
                ia.do_assert(
                    isinstance(batch, Batch),
                    "Expected batch returned by load_batch_func to "
                    "be of class imgaug.Batch, got %s." % (type(batch), ))
                batch_pickled = pickle.dumps(batch, protocol=-1)
                while not join_signal.is_set():
                    try:
                        queue_internal.put(batch_pickled, timeout=0.005)
                        break
                    except QueueFull:
                        pass
                if join_signal.is_set():
                    break
        except Exception:
            traceback.print_exc()
        finally:
            queue_internal.put("")
        time.sleep(0.01)
示例#2
0
    def _augment_images_worker(cls, augseq, queue_source, queue_result,
                               seedval):
        """
        Augment endlessly images in the source queue.

        This is a worker function for that endlessly queries the source queue
        (input batches), augments batches in it and sends the result to the
        output queue.

        """
        np.random.seed(seedval)
        random.seed(seedval)
        augseq.reseed(seedval)
        iarandom.seed(seedval)

        loader_finished = False

        while not loader_finished:
            # wait for a new batch in the source queue and load it
            try:
                batch_str = queue_source.get(timeout=0.1)
                batch = pickle.loads(batch_str)
                if batch is None:
                    loader_finished = True
                    # put it back in so that other workers know that the
                    # loading queue is finished
                    queue_source.put(pickle.dumps(None, protocol=-1))
                else:
                    batch_aug = augseq.augment_batch(batch)

                    # send augmented batch to output queue
                    batch_str = pickle.dumps(batch_aug, protocol=-1)
                    queue_result.put(batch_str)
            except QueueEmpty:
                time.sleep(0.01)

        queue_result.put(pickle.dumps(None, protocol=-1))
        time.sleep(0.01)
示例#3
0
def main():
    img = data.astronaut()
    img = ia.imresize_single_image(img, (64, 64))
    aug = iaa.Fliplr(0.5)
    unseeded1 = aug.draw_grid(img, cols=8, rows=1)
    unseeded2 = aug.draw_grid(img, cols=8, rows=1)

    iarandom.seed(1000)
    seeded1 = aug.draw_grid(img, cols=8, rows=1)
    seeded2 = aug.draw_grid(img, cols=8, rows=1)

    iarandom.seed(1000)
    reseeded1 = aug.draw_grid(img, cols=8, rows=1)
    reseeded2 = aug.draw_grid(img, cols=8, rows=1)

    iarandom.seed(1001)
    reseeded3 = aug.draw_grid(img, cols=8, rows=1)
    reseeded4 = aug.draw_grid(img, cols=8, rows=1)

    all_rows = np.vstack([
        unseeded1, unseeded2, seeded1, seeded2, reseeded1, reseeded2,
        reseeded3, reseeded4
    ])
    ia.imshow(all_rows)
示例#4
0
 def wrapper(*args, **kwargs):
     import imgaug.random as iarandom
     iarandom.seed(0)
     func(*args, **kwargs)
示例#5
0
def _reseed_global_local(base_seed, augseq):
    seed_global = _derive_seed(base_seed, -10**9)
    seed_local = _derive_seed(base_seed)
    iarandom.seed(seed_global)
    augseq.reseed(seed_local)
示例#6
0
def reseed(seed=0):
    iarandom.seed(seed)
    np.random.seed(seed)
    random.seed(seed)
from imgaug import augmenters as iaa
import imgaug as ia
import imgaug.random as iarandom

iarandom.seed(1)


def main():
    img = ia.quokka(size=(128, 128), extract="square")

    aug = iaa.ChannelShuffle()
    imgs_aug = aug.augment_images([img] * 64)
    ia.imshow(ia.draw_grid(imgs_aug))

    aug = iaa.ChannelShuffle(p=0.1)
    imgs_aug = aug.augment_images([img] * 64)
    ia.imshow(ia.draw_grid(imgs_aug))

    aug = iaa.ChannelShuffle(p=1.0, channels=[0, 1])
    imgs_aug = aug.augment_images([img] * 64)
    ia.imshow(ia.draw_grid(imgs_aug))

    aug = iaa.ChannelShuffle(p=1.0, channels=[1, 2])
    imgs_aug = aug.augment_images([img] * 64)
    ia.imshow(ia.draw_grid(imgs_aug))

    aug = iaa.ChannelShuffle(p=1.0, channels=[1, 1, 2])
    imgs_aug = aug.augment_images([img] * 64)
    ia.imshow(ia.draw_grid(imgs_aug))

    aug = iaa.ChannelShuffle(p=1.0, channels=ia.ALL)
示例#8
0
import os

try:
    SEED = int(os.getenv('SEED'))
except:
    SEED = 0
import imgaug.augmenters as iaa
import numpy as np
from imgaug.random import seed

seed(SEED)
from imgaug.augmentables.segmaps import SegmentationMapsOnImage


def just_crop(input_size=320):
    seq = iaa.CropToFixedSize(position='center', width=input_size, height=input_size).to_deterministic()
    return seq


STATE = None


class Augmenter:
    """Define augmentation sequences"""

    def __init__(self, input_size=320):
        """Input shape always stay the same after the augmentation, while value be change for a same Augmenter object"""
        self.just_crop = iaa.CropToFixedSize(position='center', width=input_size, height=input_size)
        self.seq_shape = self.get_seq_shape(input_size).to_deterministic()  # iaa.Noop()
        self.seq_val = self.get_seq_val()  # iaa.Noop() self.get_seq_val()
        self.seq_val1 = self.get_seq_val()
from __future__ import print_function, division

import numpy as np

import imgaug as ia
import imgaug.random as iarandom
from imgaug import augmenters as iaa

iarandom.seed(3)


def main():
    image = ia.data.quokka(size=0.5)
    print(image.shape)
    kps = [
        ia.KeypointsOnImage(
            [
                ia.Keypoint(x=123, y=102),
                ia.Keypoint(x=182, y=98),
                ia.Keypoint(x=155, y=134),
                ia.Keypoint(x=-20, y=20)
            ],
            shape=(image.shape[0], image.shape[1])
        )
    ]
    print("image shape:", image.shape)

    augs = [
        iaa.PiecewiseAffine(scale=0.05),
        iaa.PiecewiseAffine(scale=0.1),
        iaa.PiecewiseAffine(scale=0.2)