from future import absolute_import, division, print_function, unicode_literals
TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
Helper libraries
import numpy as np
import matplotlib.pyplot as plt
model = keras.Sequential([
keras.layers.Flatten(input_shape=(20, 20)),
keras.layers.Dense(128, activation=‘relu’),
keras.layers.Dense(10, activation=‘softmax’)
])
model.compile(optimizer=tf.train.AdamOptimizer(0.001),
#loss=‘categorical_crossentropy’,
loss=‘sparse_categorical_crossentropy’,
metrics=[‘accuracy’])
imageGrayScale =image.mean(axis=2).astype(np.float32)
#imagesGrayScale = imageGrayScale.reshape(1, 20, 20, 1)
print(imageGrayScale.shape)
image1GrayScale =image1.mean(axis=2).astype(np.float32)
#images1GrayScale =image1GrayScale.reshape(1, 20, 20, 1)
print(image1GrayScale.shape)
train_images = np.array([imageGrayScale, image1GrayScale], dtype=np.float32)
train_labels = np.array([yCat, yButterFly], dtype=np.float32)
model.fit(train_images, train_labels, epochs=5)
Example of a picture
index = 53
iNonCat=train_set_x_orig[index]
iNonCat=iNonCat[20:40, 20:40]
#plt.imshow(iCat) # You should see a cat image
yNonCat = train_set_y[:, index]
y_class = classes[np.squeeze(train_set_y[:, index])].decode(“utf-8”)
print(yNonCat)
print(y_class)
index = 54
iCat2=train_set_x_orig[index]
iCat2=iCat2[20:40, 20:40]
plt.imshow(iCat2) # You should see a cat image
yCat2 = train_set_y[:, index]
y_class = classes[np.squeeze(train_set_y[:, index])].decode(“utf-8”)
print(yCat2)
print(y_class)
imageGrayScale =iNonCat.mean(axis=2).astype(np.float32)
#imagesGrayScale = imageGrayScale.reshape(1, 20, 20, 1)
print(imageGrayScale.shape)
image1GrayScale =iCat2.mean(axis=2).astype(np.float32)
#images1GrayScale =image1GrayScale.reshape(1, 20, 20, 1)
print(image1GrayScale.shape)
test_images = np.array([imageGrayScale, image1GrayScale], dtype=np.float32)
test_labels = np.array([yNonCat, yCat2], dtype=np.float32)
test_loss, test_acc = model.evaluate(test_images, test_labels)
print(’\nTest loss:’, test_loss)
print(’\nTest accuracy:’, test_acc)
predictions = model.predict(test_images)
print(predictions)
print(model(test_images))