Advertisement
hendriawan

day2-03-cnn-evaluate

Nov 29th, 2022
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import tensorflow
  2. from tensorflow.keras.datasets import mnist
  3. from tensorflow.keras.models import load_model
  4. from tensorflow.keras.layers import Dropout, Flatten
  5.  
  6. import matplotlib.pyplot as plt
  7.  
  8. (trainX, trainY), (testX, testY) = mnist.load_data()
  9.  
  10. img_rows, img_cols = 28, 28
  11.  
  12. trainX = trainX.reshape(trainX.shape[0], img_rows, img_cols, 1)
  13. testX = testX.reshape(testX.shape[0], img_rows, img_cols, 1)
  14. input_shape = (img_rows, img_cols, 1) # 1 karena grayscale, 3 untuk berwarna
  15.  
  16. trainX = trainX.astype('float32')
  17. testX = testX.astype('float32')
  18.  
  19. trainX /= 255
  20. testX /= 255
  21.  
  22. testY = tensorflow.keras.utils.to_categorical(testY, 10)
  23. model = load_model("mnist.h5")
  24. score = model.evaluate(testX, testY)
  25. print(score)
  26.  
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement