Guest User

Untitled

a guest
Jan 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. # load data
  2. (X_train, y_train), (X_test, y_test) = cifar10.load_data()
  3. X_train = X_train.astype('float32')/256
  4. X_test = X_test.astype('float32')/256
  5. y_train = keras.utils.to_categorical(y_train)
  6. y_test = keras.utils.to_categorical(y_test)
  7.  
  8. # build a model
  9. def res_unit(x):
  10. x_shortcut = x
  11.  
  12. x = Conv2D(16, (1, 1), padding='same')(x)
  13. x = BatchNormalization()(x)
  14. x = Activation('relu')(x)
  15.  
  16. x = Conv2D(16, (3, 3), padding='same')(x)
  17. x = BatchNormalization()(x)
  18. x = Activation('relu')(x)
  19.  
  20. x = Conv2D(32, (1, 1), padding='same')(x)
  21. x = BatchNormalization()(x)
  22. x = Add()([x_shortcut, x])
  23.  
  24. x = Activation('relu')(x)
  25.  
  26. return x
  27.  
  28.  
  29. X_input = Input((X_train.shape[1:]))
  30.  
  31. X = Conv2D(32, (3, 3), padding='same')(X_input)
  32. X = BatchNormalization()(X)
  33. X = Activation('relu')(X)
  34.  
  35. X = res_unit(X)
  36. X = res_unit(X)
  37. X = res_unit(X)
  38.  
  39. X = Flatten()(X)
  40. X = Dense(32)(X)
  41. X = Activation('relu')(X)
  42. X = Dense(10)(X)
  43.  
  44. X = Activation('softmax')(X)
  45.  
  46. model = Model(inputs=X_input, outputs=X)
  47. model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  48.  
  49. # run model
  50. model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=5)
Add Comment
Please, Sign In to add comment