Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. from keras import backend as K
  2. from keras.layers import Layer
  3.  
  4. class G_MAX_AVP_P(Layer):
  5.  
  6. def __init__(self, **kwargs):
  7. #self.output_dim = input_shape[1]*input_shape[1]
  8. super(G_MAX_AVP_P, self).__init__(**kwargs)
  9.  
  10. def build(self, input_shape):
  11. super(G_MAX_AVP_P, self).build(input_shape) # Be sure to call this at the end
  12.  
  13. def call(self, x):
  14. return K.reshape(K.dot(K.transpose(x),x), [-1])
  15.  
  16. def compute_output_shape(self, input_shape):
  17. return (input_shape[0], self.input_shape[0]*self.input_shape[0])
  18.  
  19. class MULTI_ACTIVATION:
  20. @staticmethod
  21. def build(input_shape,classes):
  22. # we initialize the model
  23. input_tensor = Input(shape=input_shape)
  24. #G_MAX_AVP_P = G_MAX_AVP_P(input_shape)
  25.  
  26. # Conv Block 1
  27. x = Conv2D(64, (8, 8), input_shape=input_shape, padding='same')(input_tensor)
  28. x = BatchNormalization()(x)
  29. x = Activation('relu')(x)
  30. x = Conv2D(64, (8, 8), padding='same')(x)
  31. x = BatchNormalization()(x)
  32. x = Activation('relu')(x)
  33. x = Conv2D(64, (8, 8), padding='same')(x)
  34. x = BatchNormalization()(x)
  35. x = Activation('relu')(x)
  36.  
  37. # Conv Block 2
  38. x = Conv2D(128, (5, 5), padding='same')(x)
  39. x = BatchNormalization()(x)
  40. x = LeakyReLU(alpha=0.2)(x)
  41.  
  42. # Conv Block 3
  43. x = Conv2D(256, (3, 3), padding='same')(x)
  44. x = BatchNormalization()(x)
  45. x = PReLU()(x)
  46.  
  47. # Conv Block 4
  48. x = Conv2D(128, (5, 5), padding='same')(x)
  49. x = BatchNormalization()(x)
  50. x = ELU(alpha=0.3)(x)
  51.  
  52. x = GlobalAveragePooling2D()(x)
  53.  
  54.  
  55. x = G_MAX_AVP_P()(x)
  56.  
  57. output_tensor = Dense(units=classes, activation='softmax')(x)
  58. model = Model(input_tensor, output_tensor)
  59. model.summary()
  60.  
  61. return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement