<jupyter_start><jupyter_text>Image Classification with Keras and Tensorflow 1.x

--- [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/kyle-w-brown/tensorflow-1.x.git/HEAD) Getting started with tensorflow<jupyter_code>%tensorflow_version 1.x
import tensorflow as tf<jupyter_output>TensorFlow 1.x selected.<jupyter_text>Load and prepare the [MNIST](http://yann.lecun.com/exdb/mnist/) dataset. Convert the samples from integers to floating-point numbers:<jupyter_code>mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434 [==============================] - 0s 0us/step<jupyter_text>Build the `tf.keras` model by stacking layers. Select an optimizer and loss function used for training:<jupyter_code>model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(512, activation=tf.nn.relu),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)

model.evaluate(x_test, y_test)<jupyter_output>Train on 60000 samples
Epoch 1/5
60000/60000 [==============================] - 12s 204us/sample - loss: 0.2197 - acc: 0.9344
Epoch 2/5
60000/60000 [==============================] - 11s 189us/sample - loss: 0.0963 - acc: 0.9707
Epoch 3/5
60000/60000 [==============================] - 11s 188us/sample - loss: 0.0695 - acc: 0.9780
Epoch 4/5
60000/60000 [==============================] - 11s 186us/sample - loss: 0.0528 - acc: 0.9829
Epoch 5/5
60000/60000 [==============================] - 11s 182us/sample - loss: 0.0437 - acc: 0.9855
10000/10000 [==============================] - 1s 72us/sample - loss: 0.0697 - acc: 0.9785<jupyter_text>You’ve now trained an image classifier with ~98% accuracy on this dataset. See [Get Started with TensorFlow](https://www.tensorflow.org/get_started/) to learn more.<jupyter_code>from keras.datasets import mnist
from keras.models import Sequential 
from keras.layers.core import Dense, Activation
from keras.utils import np_utils

(X_train, Y_train), (X_test, Y_test) = mnist.load_data()

X_train = X_train.reshape(60000, 784)     
X_test = X_test.reshape(10000, 784)
X_train = X_train.astype('float32')     
X_test = X_test.astype('float32')     
X_train /= 255     
X_test /= 255


classes = 10
Y_train = np_utils.to_categorical(Y_train, classes)     
Y_test = np_utils.to_categorical(Y_test, classes)

input_size = 784
batch_size = 100     
hidden_neurons = 400     
epochs = 30

model = Sequential()     
model.add(Dense(hidden_neurons, input_dim=input_size)) 
model.add(Activation('relu'))     
model.add(Dense(classes, input_dim=hidden_neurons)) 
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adadelta')

model.fit(X_train, Y_train, batch_size=batch_size, epochs=epochs, verbose=1)

score = model.evaluate(X_test, Y_test, verbose=1)
print('Test accuracy:', score[1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18890920170627665, 'fraction_numerical': 0.07617306520414381, 'mean_word_length': 5.159474671669794, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '70728', 'license': 'Apache-2.0', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1187, 'n_words': 229, 'path': 'image_classification.ipynb', 'repo_name': 'kyle-w-brown/tensorflow-1.x', 'size': '3282'}