Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import keras as k
- import matplotlib.pyplot as plt
- from keras.layers import Conv2D, MaxPooling2D , Flatten , Dense
- from keras.datasets import mnist
- model = k.Sequential()
- model.add(Conv2D(kernel_size = 3, filters = 64 , activation = "relu", input_shape = (28,28,1)))
- model.add(Conv2D(64, 3,activation = "relu"))
- model.add(MaxPooling2D(2,2))
- model.add(Flatten())
- model.add(Dense(128, activation = "relu"))
- model.add(Dense(10, activation = "softmax"))
- model.compile(optimizer = "rmsprop" , loss = "categorical_crossentropy", metrics = ["accuracy"])
- (x_train, y_train),(x_test, y_test) = mnist.load_data()
- ohl = k.utils.to_categorical(y_train, 10)
- plt.imshow(x_train[0])
- plt.show()
- print(y_train[0])
- x_train = np.reshape(x_train, (-1,28, 28,1))/255
- model.fit(x_train, ohl, epochs = 3)
- print(model.summary())
- print(x_train.shape)
- g = int(input("Pick a Number (0-100): "))
- image =x_test[g]
- image = np.reshape(image , (1,28,28,1))
- print(model.predict([image]))
- dis = np.reshape(image , (28,28))/255
- plt.imshow(dis)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement