Ejemplo n.º 1
0
    def test_color_images(self):
        # create model instance
        mnist_test = Cifar10CNN()
        mnist_test.max_epochs = 1
        mnist_test.callbacks = ErrorOnNaN()

        mnist_test.train(x_train_color, y_train)
        pred = mnist_test.test(x_test_color)
        test_num = y_test.shape[0]
        assert (np.sum(np.argmax(pred, axis=1) == y_test)) / test_num > 0.9  # assert accuracy

        # create model instance for binary classification
        mnist_test = Galaxy10CNN()
        mnist_test.max_epochs = 1
        mnist_test.mc_num = 3

        mnist_test.train(x_train[:200], y_train[:200])
        prediction = mnist_test.test(x_test[:200])

        mnist_test.save('cifar10_test')
        mnist_reloaded = load_folder("cifar10_test")
        prediction_loaded = mnist_reloaded.test(x_test[:200])
        mnist_reloaded.jacobian(x_test[:2], mean_output=True, mc_num=2)
        # mnist_reloaded.hessian_diag(x_test[:10], mean_output=True, mc_num=2)

        # Cifar10_CNN is deterministic
        np.testing.assert_array_equal(prediction, prediction_loaded)
Ejemplo n.º 2
0
    def test_color_images(self):
        # test colored 8bit images
        (x_train, y_train), (x_test, y_test) = mnist.load_data()
        x_train = np.random.randint(0, 255, size=(1000, 28, 28, 3))
        x_test = np.random.randint(0, 255, size=(100, 28, 28, 3))
        y_train = y_train[:1000]
        y_train = np_utils.to_categorical(y_train, 10)
        # To convert to desirable type

        x_train = x_train.astype(np.float32)
        x_test = x_test.astype(np.float32)
        y_train = y_train.astype(np.float32)

        # create model instance
        mnist_test = Cifar10CNN()
        mnist_test.max_epochs = 1
        mnist_test.callbacks = ErrorOnNaN()

        mnist_test.train(x_train, y_train[:1000])
        mnist_test.test(x_test[:1000])

        # create model instance for binary classification
        mnist_test = Galaxy10CNN()
        mnist_test.max_epochs = 1

        mnist_test.train(x_train[:1000], y_train[:1000])
        prediction = mnist_test.test(x_test[:1000])

        mnist_test.save('cifar10_test')
        mnist_reloaded = load_folder("cifar10_test")
        prediction_loaded = mnist_reloaded.test(x_test[:1000])
        mnist_reloaded.jacobian(x_test[:10], mean_output=True, mc_num=2)

        # Cifar10_CNN is deterministic
        np.testing.assert_array_equal(prediction, prediction_loaded)
Ejemplo n.º 3
0
 def test_nomodel(self):
     nomodel = Galaxy10CNN()
     self.assertRaises(AttributeError, nomodel.summary)
     self.assertRaises(AttributeError, nomodel.save)
     self.assertRaises(AttributeError, nomodel.get_weights)
     self.assertRaises(AttributeError, nomodel.test, np.zeros(100))