def testInit(self): # Creates two image generator objects without shuffling. # Calling next on either one should result in the same output from generator import ImageGenerator gen = ImageGenerator(self.file_path, self.label_path, 12, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) gen2 = ImageGenerator(self.file_path, self.label_path, 12, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) np.testing.assert_almost_equal(gen.next()[0], gen2.next()[0]) np.testing.assert_almost_equal(gen.next()[1], gen2.next()[1])
def testInit(self): from generator import ImageGenerator gen = ImageGenerator(self.file_path, self.json_path, 12, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) gen2 = ImageGenerator(self.file_path, self.json_path, 12, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) np.testing.assert_almost_equal(gen.next()[0], gen2.next()[0]) np.testing.assert_almost_equal(gen.next()[1], gen2.next()[1])
def testShuffle(self): # Creates two image generator objects. # Since shuffle is enabled for one image generator the output should be different. from generator import ImageGenerator gen = ImageGenerator(self.file_path, self.label_path, 10, [32, 32, 3], rotation=False, mirroring=False, shuffle=True) gen2 = ImageGenerator(self.file_path, self.label_path, 10, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) np.testing.assert_raises(AssertionError, np.testing.assert_array_equal, gen.next()[0], gen2.next()[0]) np.testing.assert_raises(AssertionError, np.testing.assert_array_equal, gen.next()[1], gen2.next()[1])
def testResetIndex(self): # Data contains 100 image samples, for a batchsize of 60 an # overlap of 20 occurs, therefore the first 20 elements # of the first batch should be equal to the last 20 of the second batch from generator import ImageGenerator gen = ImageGenerator(self.file_path, self.label_path, 60, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) b1 = gen.next()[0] b2 = gen.next()[0] np.testing.assert_almost_equal(b1[:20], b2[40:])
def testShuffle(self): from generator import ImageGenerator gen = ImageGenerator(self.file_path, self.json_path, 10, [32, 32, 3], rotation=False, mirroring=False, shuffle=True) gen2 = ImageGenerator(self.file_path, self.json_path, 10, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) np.testing.assert_raises(AssertionError, np.testing.assert_array_equal, gen.next()[0], gen2.next()[0]) np.testing.assert_raises(AssertionError, np.testing.assert_array_equal, gen.next()[1], gen2.next()[1])
def testResetIndex(self): from generator import ImageGenerator # Data contains 100 image samples, create two overlapping batches gen = ImageGenerator(self.file_path, self.json_path, 60, [32, 32, 3], rotation=False, mirroring=False, shuffle=False) b1 = gen.next()[0] b2 = gen.next()[0] np.testing.assert_almost_equal(b1[:20], b2[40:])