Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
print("TensorFlow version:", tf.__version__)
|
| 3 |
+
|
| 4 |
+
mnist = tf.keras.datasets.mnist
|
| 5 |
+
|
| 6 |
+
(x_train, y_train), (x_test, y_test) = mnist.load_data()
|
| 7 |
+
x_train, x_test = x_train / 255.0, x_test / 255.0
|
| 8 |
+
|
| 9 |
+
model = tf.keras.models.Sequential([
|
| 10 |
+
tf.keras.layers.Flatten(input_shape=(28, 28)),
|
| 11 |
+
tf.keras.layers.Dense(128, activation='relu'),
|
| 12 |
+
tf.keras.layers.Dropout(0.2),
|
| 13 |
+
tf.keras.layers.Dense(10)
|
| 14 |
+
])
|
| 15 |
+
|
| 16 |
+
predictions = model(x_train[:1]).numpy()
|
| 17 |
+
predictions
|
| 18 |
+
|
| 19 |
+
tf.nn.softmax(predictions).numpy()
|
| 20 |
+
|
| 21 |
+
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
|
| 22 |
+
|
| 23 |
+
loss_fn(y_train[:1], predictions).numpy()
|
| 24 |
+
|
| 25 |
+
model.compile(optimizer='adam',
|
| 26 |
+
loss=loss_fn,
|
| 27 |
+
metrics=['accuracy'])
|
| 28 |
+
|
| 29 |
+
model.fit(x_train, y_train, epochs=5)
|
| 30 |
+
|
| 31 |
+
model.evaluate(x_test, y_test, verbose=2)
|