Ejemplo n.º 1
0
 def test_one_channel(self):
     mnist = input_data.read_data_sets("tmp/MNIST_data/")
     x = np.reshape(mnist.test.images[0:2], (-1, 28, 28, 1))
     preprocess = JpegCompression()
     compressed_x = preprocess(x, quality=70)
     self.assertTrue((compressed_x.shape == x.shape))
     self.assertTrue((compressed_x <= 1.0).all())
     self.assertTrue((compressed_x >= 0.0).all())
Ejemplo n.º 2
0
 def test_one_channel(self):
     (x_train, _), (_, _), _, _ = load_mnist()
     x_train = x_train[:2]
     preprocess = JpegCompression()
     compressed_x, _ = preprocess(x_train, quality=70)
     self.assertTrue((compressed_x.shape == x_train.shape))
     self.assertTrue((compressed_x <= 1.0).all())
     self.assertTrue((compressed_x >= 0.0).all())
 def test_three_channels(self):
     (train_features, _), (_, _) = cifar10.load_data()
     x = train_features[:2] / 255.0
     preprocess = JpegCompression()
     compressed_x = preprocess(x, quality=80)
     self.assertTrue((compressed_x.shape == x.shape))
     self.assertTrue((compressed_x <= 1.0).all())
     self.assertTrue((compressed_x >= 0.0).all())
 def test_channel_index(self):
     (train_features, _), (_, _) = cifar10.load_data()
     x = train_features[:2] / 255.0
     x = np.swapaxes(x, 1, 3)
     preprocess = JpegCompression(channel_index=1)
     compressed_x = preprocess(x, quality=80)
     self.assertTrue((compressed_x.shape == x.shape))
     self.assertTrue((compressed_x <= 1.0).all())
     self.assertTrue((compressed_x >= 0.0).all())
Ejemplo n.º 5
0
    def test_failure_feature_vectors(self):
        x = np.random.rand(10, 3)
        preprocess = JpegCompression(channel_index=1, quality=80)

        # Assert that value error is raised for feature vectors
        with self.assertRaises(ValueError) as context:
            preprocess(x)

        self.assertTrue('Feature vectors detected.' in str(context.exception))