def train_tensorflow(batch_size, epochs, n_classes):
    mnist_data = input_data.read_data_sets('MNIST_data', one_hot=True)
    (test_images, test_labels) = (mnist_data.test.images, mnist_data.test.labels)
    input_size = 784
    x_input = tf.placeholder(tf.float32, shape=[None, input_size])
    y_input = tf.placeholder(tf.float32, shape=[None, n_classes])
    bool_dropout = tf.placeholder(tf.bool)
    logits = create_simple_cnn_model(x_input, y_input, bool_dropout)
    loss_operation = calculate_loss(logits, y_input)
    optimizer = optimize_weights(loss_operation)
    accuracy_operation = calculate_accuracy(logits, y_input)
    session = tf.Session()
    session.run(tf.global_variables_initializer())
    merged_summary_operation = tf.summary.merge_all()
    train_summary_writer = tf.summary.FileWriter('/tmp/train', session.graph)
    test_summary_writer = tf.summary.FileWriter('/tmp/test')
    for batch_n in range(epochs):
        mnist_batch = mnist_data.train.next_batch(batch_size)
        (train_images, train_labels) = (mnist_batch[0], mnist_batch[1])
        (_, merged_summary) = session.run([optimizer, merged_summary_operation], feed_dict={x_input: train_images, y_input: train_labels, bool_dropout: True})
        train_summary_writer.add_summary(merged_summary, batch_n)
        if ((batch_n % 10) == 0):
            (merged_summary, _) = session.run([merged_summary_operation, accuracy_operation], feed_dict={x_input: test_images, y_input: test_labels, bool_dropout: False})
            test_summary_writer.add_summary(merged_summary, batch_n)
def train_tensorflow(batch_size, epochs, n_classes):
    mnist_data = input_data.read_data_sets('MNIST_data', one_hot=True)
    (test_images, test_labels) = (mnist_data.test.images, mnist_data.test.labels)
    input_size = 784
    x_input = tf.placeholder(tf.float32, shape=[None, input_size])
    y_input = tf.placeholder(tf.float32, shape=[None, n_classes])
    bool_dropout = tf.placeholder(tf.bool)
    logits = create_simple_cnn_model(x_input, y_input, bool_dropout)
    loss_operation = calculate_loss(logits, y_input)
    optimizer = optimize_weights(loss_operation)
    accuracy_operation = calculate_accuracy(logits, y_input)
    session = tf.Session()
    session.run(tf.global_variables_initializer())
    merged_summary_operation = tf.summary.merge_all()
    train_summary_writer = tf.summary.FileWriter('/tmp/train', session.graph)
    test_summary_writer = tf.summary.FileWriter('/tmp/test')
    for batch_n in range(epochs):
        mnist_batch = mnist_data.train.next_batch(batch_size)
        (train_images, train_labels) = (mnist_batch[0], mnist_batch[1])
        (_, merged_summary) = session.run([optimizer, merged_summary_operation], feed_dict={x_input: train_images, y_input: train_labels, bool_dropout: True})
        train_summary_writer.add_summary(merged_summary, batch_n)
        if ((batch_n % 10) == 0):
            (merged_summary, _) = session.run([merged_summary_operation, accuracy_operation], feed_dict={x_input: test_images, y_input: test_labels, bool_dropout: False})
            test_summary_writer.add_summary(merged_summary, batch_n)