def test_accuracy_bug(self): import tensor_dynamic.data.input_data as mnist data = mnist.read_data_sets("../data/MNIST_data", one_hot=True) inputs = tf.placeholder(tf.float32, shape=(None, 784)) input_layer = InputLayer(inputs) outputs = Layer(input_layer, 10, self.session, non_liniarity=tf.sigmoid) trainer = CategoricalTrainer(outputs, 0.1) trainer.train(data.validation.images, data.validation.labels) # this was throwing an exception accuracy = trainer.accuracy(data.validation.images, data.validation.labels) self.assertLessEqual(accuracy, 100.) self.assertGreaterEqual(accuracy, 0.)
def test_mnist(self): data = self.mnist_data input = InputLayer(self.MNIST_INPUT_NODES) d_1 = DuelStateReluLayer(input, 3, width_regularizer_constant=1e-7, width_binarizer_constant=1e-10, session=self.session) d_2 = DuelStateReluLayer(d_1, 3, width_regularizer_constant=1e-7, width_binarizer_constant=1e-10, ) output = HiddenLayer(d_2, self.MNIST_OUTPUT_NODES) trainer = CategoricalTrainer(output, 0.1) end_epoch = data.train.epochs_completed + 20 while data.train.epochs_completed <= end_epoch: train_x, train_y = data.train.next_batch(100) trainer.train(train_x, train_y) accuracy, cost = trainer.accuracy(data.test.features, data.test.labels) print(accuracy, cost) print("active nodes ", d_1.active_nodes()) self.assertGreater(accuracy, 70.)
def test_mnist(self): data = self.mnist_data input = InputLayer(self.MNIST_INPUT_NODES) d_1 = DuelStateReluLayer(input, 3, width_regularizer_constant=1e-7, width_binarizer_constant=1e-10, session=self.session) # when we add in batch norm layers we find that no active nodes are created, width is always less than 0.5? # bn_1 = BatchNormLayer(d_1) d_2 = DuelStateReluLayer(d_1, 3, width_regularizer_constant=1e-7, width_binarizer_constant=1e-10, ) # bn_2 = BatchNormLayer(d_2) output = Layer(d_2, self.MNIST_OUTPUT_NODES) trainer = CategoricalTrainer(output, 0.1) end_epoch = data.train.epochs_completed + 20 while data.train.epochs_completed <= end_epoch: train_x, train_y = data.train.next_batch(100) trainer.train(train_x, train_y) accuracy, cost = trainer.accuracy(data.test.images, data.test.labels) print(accuracy, cost) print("active nodes ", d_1.active_nodes()) self.assertGreater(accuracy, 70.)
def test_mnist_start_large(self): data = self.mnist_data input_layer = InputLayer(784) hidden_1 = DuelStateReluLayer(input_layer, 200, session=self.session, inactive_nodes_to_leave=200) output = HiddenLayer(hidden_1, self.MNIST_OUTPUT_NODES, session=self.session) trainer = CategoricalTrainer(output, 0.1) end_epoch = data.train.epochs_completed + 5 print(trainer.accuracy(data.test.features, data.test.labels)) while data.train.epochs_completed <= end_epoch: train_x, train_y = data.train.next_batch(100) trainer.train(train_x, train_y) accuracy, cost = trainer.accuracy(data.test.features, data.test.labels) print(accuracy, cost) # print(output.active_nodes()) print(hidden_1.active_nodes()) self.assertGreater(accuracy, 90.) # self.assertEqual(output.active_nodes(), self.MNIST_OUTPUT_NODES, msg='expect all output nodes to be active') self.assertLess(hidden_1.active_nodes(), hidden_1.output_nodes, msg='expect not all hidden nodes to be active')
def test_mnist_start_large(self): data = self.mnist_data input_layer = InputLayer(784) hidden_1 = DuelStateReluLayer(input_layer, 200, session=self.session, inactive_nodes_to_leave=200) output = Layer(hidden_1, self.MNIST_OUTPUT_NODES, session=self.session) trainer = CategoricalTrainer(output, 0.1) end_epoch = data.train.epochs_completed + 5 print(trainer.accuracy(data.test.images, data.test.labels)) while data.train.epochs_completed <= end_epoch: train_x, train_y = data.train.next_batch(100) trainer.train(train_x, train_y) accuracy, cost = trainer.accuracy(data.test.images, data.test.labels) print(accuracy, cost) # print(output.active_nodes()) print(hidden_1.active_nodes()) self.assertGreater(accuracy, 90.) # self.assertEqual(output.active_nodes(), self.MNIST_OUTPUT_NODES, msg='expect all output nodes to be active') self.assertLess(hidden_1.active_nodes(), hidden_1.output_nodes, msg='expect not all hidden nodes to be active')