└── image classification /image classification: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from tensorflow import keras 3 | from tensorflow.keras import datasets, layers, models 4 | import matplotlib.pyplot as plt 5 | %matplotlib inline 6 | import numpy as np 7 | 8 | 9 | (X_train, y_train) , (X_test, y_test) = keras.datasets.mnist.load_data() 10 | 11 | X_train.shape 12 | 13 | 14 | X_test.shape 15 | 16 | 17 | X_train[0].shape 18 | 19 | plt.matshow(X_train[0]) 20 | 21 | plt.matshow(X_train[0]) 22 | 23 | X_train = X_train / 255 24 | X_test = X_test / 255 25 | 26 | model = keras.Sequential([ 27 | 28 | layers.Conv2D(30, (3,3), activation='relu', input_shape=(28, 28, 1)), 29 | layers.MaxPooling2D((2,2)), 30 | 31 | layers.Flatten(), 32 | layers.Dense(100, activation='relu'), 33 | keras.layers.Dense(10, activation='sigmoid') 34 | ]) 35 | 36 | 37 | model.compile(optimizer='adam', 38 | loss='sparse_categorical_crossentropy', 39 | metrics=['accuracy']) 40 | 41 | model.fit(X_train, y_train, epochs=5) 42 | 43 | y_train[:5] 44 | 45 | model.evaluate(X_test,y_test) 46 | --------------------------------------------------------------------------------