Skip to content

Instantly share code, notes, and snippets.

View bartubozkurt's full-sized avatar
🎯
Focusing

Bartu Bozkurt bartubozkurt

🎯
Focusing
View GitHub Profile
test_labels[0]
# 9
np.argmax(predictions[0])
# 9
predictions[0]
'''
array([2.9212106e-07, 1.6208847e-10, 1.3363140e-08, 2.7341349e-09,
5.5379962e-10, 4.5457238e-04, 4.2226111e-06, 4.4925120e-03,
5.8868943e-07, 9.9504781e-01], dtype=float32)
'''
probability_model = tf.keras.Sequential([model,
tf.keras.layers.Softmax()])
predictions = probability_model.predict(test_images)
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print('\nTest accuracy:', test_acc)
'''
313/313 - 0s - loss: 0.3413 - accuracy: 0.8814
Test accuracy: 0.8813999891281128 '''
model.fit(train_images, train_labels, epochs=10)
'''
Epoch 1/10
1875/1875 [==============================] - 3s 1ms/step - loss: 0.4982 - accuracy: 0.8256
Epoch 2/10
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3747 - accuracy: 0.8658
Epoch 3/10
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3356 - accuracy: 0.8770
Epoch 4/10
1875/1875 [==============================] - 3s 1ms/step - loss: 0.3112 - accuracy: 0.8856
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10)
])
plt.figure(figsize=(10,10))
for i in range(25):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i], cmap=plt.cm.binary)
plt.xlabel(class_names[train_labels[i]])
plt.show()
train_images = train_images / 255.0
test_images = test_images / 255.0