-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourse_1_Week_2_Project_2.py
62 lines (43 loc) · 1.78 KB
/
Course_1_Week_2_Project_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
This is is a part of the DeepLearning.AI TensorFlow Developer Professional Certificate offered on Coursera.
All copyrights belong to them. I am sharing this work here to showcase the projects I have worked on
Course: Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning
Week 2: Introduction to Computer Vision
Aim: Implementing Callbacks
"""
import tensorflow as tf
import numpy as np
from tensorflow import keras
import matplotlib.pyplot as plt
"""
Implementing Callback
"""
class mycallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if (logs.get("acc")>0.85):
print("\n Reached 85% accuracy, so stopping training!")
self.model.stop_training=True
callback=mycallback()
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (testing_images, testing_labels) = mnist.load_data()
plt.imshow(training_images[0])
plt.show()
training_images=training_images/255
testing_images=testing_images/255
model= tf.keras.models.Sequential([
keras.layers.Flatten(),
keras.layers.Dense(128, activation="relu"),
keras.layers.Dense(10, activation="softmax")
])
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["acc"])
history = model.fit(training_images, training_labels, validation_data=(testing_images, testing_labels), epochs=5, callbacks=[callback])
"""model.evaluate(training_images, training_labels)"""
def plot_graphs(history,string):
plt.plot(history.history[string])
plt.plot(history.history['val_' + string])
plt.xlabel("Epochs")
plt.ylabel(string)
plt.legend([string, 'val_' + string])
plt.show()
plot_graphs(history,"acc")
plot_graphs(history,"loss")