Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. from keras.layers import Conv2D, Activation, MaxPooling2D, Flatten, Dense
  2. from keras.layers import Input, ZeroPadding2D
  3. from keras.layers import Dropout, BatchNormalization
  4. from keras.models import Model
  5. from keras.utils import plot_model
  6.  
  7.  
  8. input_shape=(64, 64, 3)
  9.  
  10. # Define the input placeholder as a tensor with shape input_shape.
  11. X_input = Input(input_shape)
  12.  
  13. # Zero-Padding: pads the border of X_input with zeroes
  14. X = ZeroPadding2D((3, 3))(X_input)
  15.  
  16. # CONV -> BN -> RELU
  17. X = Conv2D(filters=32, kernel_size=(7, 7), strides=(1, 1), padding='same', name='conv0')(X)
  18. X = BatchNormalization(axis=3, name='bn0')(X)
  19. X = Activation('relu')(X)
  20.  
  21. # MAXPOOL
  22. # padding: valid (default) or same
  23. X = MaxPooling2D(pool_size=(2, 2), strides=(2,2), padding='valid', name='max_pool1')(X)
  24.  
  25. # CONV -> RELU
  26. X = Conv2D(filters=64, kernel_size=(3, 3), strides=(1, 1), padding='same', activation='relu', name='conv1')(X)
  27.  
  28. # MAXPOOL
  29. # strides default to pool_size
  30. X = MaxPooling2D(pool_size=(2, 2), name='max_pool2')(X)
  31.  
  32. # Flatten X: convert X to a vector with shape (batch_size, h * w * c)
  33. X = Flatten()(X)
  34.  
  35. # Fully connected layer
  36. X = Dense(units=512, activation='relu', name='fc0')(X)
  37. X = Dropout(0.25)(X)
  38. # softmax -> multi-class classification, units = num_classes
  39. # sigmoid -> binary classification, units = 1
  40. X = Dense(units=1, activation='sigmoid', name='fc1')(X)
  41.  
  42. # Create model
  43. model = Model(inputs=X_input, outputs=X, name='Model')
  44.  
  45. model.summary()
  46.  
  47. plot_model(model, show_shapes=True, show_layer_names=True, to_file='model.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement