Advertisement
Guest User

code1

a guest
Jun 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import numpy as np
  2. import keras as k
  3. import matplotlib.pyplot as plt
  4.  
  5. from keras.layers import Conv2D, MaxPooling2D , Flatten , Dense
  6.  
  7. from keras.datasets import mnist
  8.  
  9. model = k.Sequential()
  10. model.add(Conv2D(kernel_size = 3, filters = 64 , activation = "relu", input_shape = (28,28,1)))
  11.  
  12. model.add(Conv2D(64, 3,activation = "relu"))
  13.  
  14. model.add(MaxPooling2D(2,2))
  15.  
  16. model.add(Flatten())
  17.  
  18. model.add(Dense(128, activation = "relu"))
  19.  
  20. model.add(Dense(10, activation = "softmax"))
  21.  
  22.  
  23.  
  24. model.compile(optimizer = "rmsprop" , loss = "categorical_crossentropy", metrics = ["accuracy"])
  25.  
  26. (x_train, y_train),(x_test, y_test) = mnist.load_data()
  27. ohl = k.utils.to_categorical(y_train, 10)
  28.  
  29. plt.imshow(x_train[0])
  30.  
  31. plt.show()
  32.  
  33. print(y_train[0])
  34.  
  35. x_train = np.reshape(x_train, (-1,28, 28,1))/255
  36.  
  37. model.fit(x_train, ohl, epochs = 3)
  38.  
  39.  
  40. print(model.summary())
  41.  
  42. print(x_train.shape)
  43.  
  44. g = int(input("Pick a Number (0-100): "))
  45. image =x_test[g]
  46. image = np.reshape(image , (1,28,28,1))
  47. print(model.predict([image]))
  48. dis = np.reshape(image , (28,28))/255
  49. plt.imshow(dis)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement