コード例 #1
0
    def test_random_distributions_2D(self):
        ### test whether all 4 possible mirrorings occur in approximately equal frquencies in 2D

        batch_gen = BasicDataLoader((self.x_2D, self.y_2D), self.batch_size, number_of_threads_in_multithreaded=None)
        batch_gen = SingleThreadedAugmenter(batch_gen, MirrorTransform((0, 1)))

        counts = np.zeros(shape=(4,))

        for b in range(self.num_batches):
            batch = next(batch_gen)

            for ix in range(self.batch_size):
                if (batch['data'][ix, :, :, :] == self.cam_left).all():
                    counts[0] = counts[0] + 1

                elif (batch['data'][ix, :, :, :] == self.cam_updown).all():
                    counts[1] = counts[1] + 1

                elif (batch['data'][ix, :, :, :] == self.cam_updown_left).all():
                    counts[2] = counts[2] + 1

                elif (batch['data'][ix, :, :, :] == self.cam).all():
                    counts[3] = counts[3] + 1

        self.assertTrue([1 if (2200 < c < 2800) else 0 for c in counts] == [1]*4, "2D Images were not mirrored along "
                                                                                  "all axes with equal probability. "
                                                                                  "This may also indicate that "
                                                                                  "mirroring is not working")
コード例 #2
0
    def test_segmentations_2D(self):
        ### test whether segmentations are mirrored coherently with images

        batch_gen = BasicDataLoader((self.x_2D, self.y_2D), self.batch_size, number_of_threads_in_multithreaded=None)
        batch_gen = SingleThreadedAugmenter(batch_gen, MirrorTransform((0, 1)))

        equivalent = True

        for b in range(self.num_batches):
            batch = next(batch_gen)
            for ix in range(self.batch_size):
                if (batch['data'][ix] != batch['seg'][ix]).all():
                    equivalent = False

        self.assertTrue(equivalent, "2D images and seg were not mirrored in the same way (they should though because "
                                    "seg needs to match the corresponding data")