Advertisement
pdpd123

Untitled

Jun 12th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import keras
  2. from keras.datasets import mnist
  3. from keras.models import Sequential
  4. from keras.layers import Dense, Dropout, LeakyReLU, Conv2D
  5. from keras.optimizers import RMSprop
  6. from keras import backend as K
  7. K.tensorflow_backend._get_available_gpus()
  8. from matplotlib.pyplot import imshow
  9. import numpy as np
  10. from tensorflow.examples.tutorials.mnist import input_data
  11.  
  12. # 讀入 MNIST
  13. (x_train, y_train), (x_test, y_test) = mnist.load_data()
  14.  
  15. # the data, shuffled and split between train and test sets
  16. x_train = x_train.reshape(60000 , 784)
  17. x_test = x_test.reshape(10000, 784)
  18.  
  19. x_train = x_train.astype('float32')
  20. x_test = x_test.astype('float32')
  21. x_train /= 255
  22. x_test /= 255
  23.  
  24. # convert class vectors to binary class matrices
  25. num_classes = 10
  26. y_train = keras.utils.to_categorical(y_train, num_classes)
  27. y_test = keras.utils.to_categorical(y_test, num_classes)
  28.  
  29. print(x_train.shape, 'train samples')
  30. print(x_test.shape, 'test samples')
  31. print(y_train.shape, 'train labels')
  32. print(y_test.shape, 'test labels')
  33.  
  34. # modeling
  35. ________________________________________________
  36. ________________________________________________
  37. ________________________________________________
  38. ________________________________________________
  39.  
  40. # training
  41. ________________________________________________
  42.  
  43. # fitting
  44. ________________________________________________
  45.  
  46. # testing
  47. ________________________________________________
  48. ________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement