Last active
March 19, 2019 03:33
-
-
Save mgomes/e9051e888791bc55b2217c9459c7df9f to your computer and use it in GitHub Desktop.
Deep Neural Net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
print(tf.__version__) | |
class myCallback(tf.keras.callbacks.Callback): | |
def on_epoch_end(self, epoch, logs={}): | |
if(logs.get('loss')<0.4): | |
print("\nReached 60% accuracy so cancelling training!") | |
self.model.stop_training = True | |
callbacks = myCallback() | |
mnist = tf.keras.datasets.fashion_mnist | |
(training_images, training_labels), (test_images, test_labels) = mnist.load_data() | |
training_images=training_images/255.0 | |
test_images=test_images/255.0 | |
model = tf.keras.models.Sequential([ | |
tf.keras.layers.Flatten(), | |
tf.keras.layers.Dense(512, activation=tf.nn.relu), | |
tf.keras.layers.Dense(10, activation=tf.nn.softmax) | |
]) | |
model.compile(optimizer = 'adam', | |
loss = 'sparse_categorical_crossentropy', | |
metrics=['accuracy']) | |
model.fit(training_images, training_labels, epochs=5, callbacks=[callbacks]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment