Esempio n. 1
0
    def _thread_fun(self, thread_id):
        # create a thread-specifc RNG
        rng = randomgen.RandomGenerator(randomgen.Xoroshiro128(seed=20 + thread_id))
        rnd_normal = None
        rnd_perlin = None

        t = threading.currentThread()
        while getattr(t, 'do_run', True):

            # Prepare one of each sampling patterns
            if rnd_normal is None:
                rnd_normal = rng.standard_normal(size=self.shape, dtype='float32')
                rnd_normal /= np.linalg.norm(rnd_normal)
            if rnd_perlin is None:
                rnd_perlin = create_perlin_noise(px=self.shape[0], color=self.perlin_color, batch_size=1,
                                                  normalize=True, precalc_fade=self.perlin_fade)[0]

            # Lock and put them into the queues.
            with self.cv_not_full:
                if len(self.queue_normal) >= self.queue_lengths and len(self.queue_perlin) >= self.queue_lengths:
                    self.cv_not_full.wait()

                # Fill one or both queues.
                if len(self.queue_normal) < self.queue_lengths:
                    self.queue_normal.append(rnd_normal)
                    rnd_normal = None
                if len(self.queue_perlin) < self.queue_lengths:
                    self.queue_perlin.append(rnd_perlin)
                    rnd_perlin = None

                self.cv_not_empty.notify_all()
Esempio n. 2
0
            def sample_std_normal(thread_id, shape, dtype):
                # create a thread-specifc RNG
                rng = randomgen.RandomGenerator(
                    randomgen.Xoroshiro128(seed=20 + thread_id))

                t = threading.currentThread()
                while getattr(t, 'do_run', True):
                    rnd_normal = rng.standard_normal(size=shape, dtype=dtype)
                    rnd_normal_queue.put(rnd_normal)
Esempio n. 3
0
    def _thread_fun(self, thread_id):
        # create a thread-specifc RNG
        rng = randomgen.RandomGenerator(
            randomgen.Xoroshiro128(seed=20 + thread_id))
        rnd_normal = None
        rnd_lowfreq = None

        t = threading.currentThread()
        while getattr(t, 'do_run', True):

            # Prepare one of each sampling patterns
            if rnd_normal is None:
                rnd_normal = rng.standard_normal(size=self.shape,
                                                 dtype='float32')
                rnd_normal /= np.linalg.norm(rnd_normal)
            if rnd_lowfreq is None:

                # MODIFIED
                # There are two concurring implementations of lowfreq noise, Perlin Noise by Brunner et al. and IDCT noise by Guo et al.
                # We found them to be pretty much equivalent, but Guo's has a much simpler implementation :)
                #
                # Therefore we replaced Perlin noise with Guo's lowfreq generator.
                # ALSO, the actual noise frequency is an important hyperparameter. Brunner et al. use a constant frequency for ImageNet.
                # We found that using a random (low-ish) frequency works much better, as we can span a much larger spectrum, and also avoid the
                # round "bubbles" found in the original "Guessing Smart" paper.
                freq = rng.uniform(-5., 1.)
                freq_ratio = 1. / (1. + np.exp(-freq))

                rnd_lowfreq = create_idct_noise(size_px=299,
                                                ratio=freq_ratio,
                                                normalize=True,
                                                rng_gen=rng)
                rnd_lowfreq = (rnd_lowfreq, freq)

            # Lock and put them into the queues.
            with self.cv_not_full:
                if len(self.queue_normal) >= self.queue_lengths and len(
                        self.queue_lowfreq) >= self.queue_lengths:
                    self.cv_not_full.wait()

                # Fill one or both queues.
                if len(self.queue_normal) < self.queue_lengths:
                    self.queue_normal.append(rnd_normal)
                    rnd_normal = None
                if len(self.queue_lowfreq) < self.queue_lengths:
                    self.queue_lowfreq.append(rnd_lowfreq)
                    rnd_lowfreq = None

                self.cv_not_empty.notify_all()