SHARE
TWEET

Untitled

a guest Jul 17th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import keras
  2. from keras.datasets import mnist
  3. keras.backend.clear_session()
  4.  
  5. (x_train, y_train), (x_test, y_test) = mnist.load_data()
  6.  
  7.  
  8. def build_model():
  9.     input = keras.layers.Input((28, 28, 1))
  10.     out = keras.layers.Conv2D(16, 3, strides=2, activation='relu')(input)
  11.     out = keras.layers.Conv2D(32, 3, strides=2, activation='relu')(out)
  12.     out = keras.layers.Flatten()(out)
  13.     out = keras.layers.Dense(10)(out)
  14.     out = keras.layers.Activation('softmax')(out)
  15.  
  16.     return keras.models.Model(input, out)
  17.  
  18. model = build_model()
  19.  
  20. model.compile(
  21.     keras.optimizers.Adam(lr=0.001),
  22.     loss=keras.losses.sparse_categorical_crossentropy,
  23.     metrics=[keras.metrics.sparse_categorical_accuracy]
  24. )
  25.  
  26. batch_size = 32
  27. model.fit(
  28.     x_train[:, :, :, None],
  29.     y_train[:, None],
  30.     epochs=5,
  31.     batch_size=batch_size,
  32.     validation_split=0.05
  33. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top