def test_reading_to_numpy(self): image = PIL.Image.open("test_utils/test_image.jpg") ndarray1 = np.array(image) ndarray2 = db.read_jpg_as_numpy("test_utils/test_image.jpg") ndarray3 = db.read_jpg_as_numpy("test_utils/test_image.jpg", True) PIL.Image.fromarray(ndarray3).save("test_image2.png") self.assertTrue(np.all(ndarray1 == ndarray2)) mean_error = np.abs(ndarray1.astype(int) - ndarray3.astype(int)).mean() PIL.Image.fromarray(np.abs(ndarray1.astype(int) - ndarray3.astype(int)).astype(np.uint8)).save("test_image_diff.png") self.assertTrue(mean_error < 0.5)
def test_reading_to_numpy_does_not_exist(self): with self.assertRaises(RuntimeError) as context: db.read_jpg_as_numpy("does_not_exist") self.assertTrue('No such file does_not_exist' == context.exception.args[0])
def read_jpg_to_numpy_db_turbo(): for i in range(2000): ndarray = db.read_jpg_as_numpy( 'test_utils/test_images/%d.jpg' % (i % 200), True)
def read_jpg_to_numpy_db(): for i in range(200): ndarray = db.read_jpg_as_numpy( '/data/for_benchmark/test_utils/test_images/%d.jpg' % (i % 200))