Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. import tensorflow as tf
  2. from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, ZeroPadding2D, Input, Dropout
  3. from tensorflow.keras import Model
  4.  
  5.  
  6. class Model_Version_2_02(tf.keras.Model):
  7. def __init__(self):
  8. super(Model_Version_2_02, self).__init__()
  9.  
  10. # first convolutional layer
  11. self.conv1 = Conv2D(32, # filters
  12. (3, 3), # Kernel size
  13. strides=(1, 1), # Stride
  14. padding='same', # Same refers to same padding as previous layer.
  15. data_format=None,
  16. # It should be defined if the dimensions are structured in non standard approach
  17. dilation_rate=(1, 1), # how dilated the picture is
  18. activation='relu', # Activation function
  19. use_bias=True, # Enable bias
  20. kernel_initializer='glorot_uniform', # initialiser of filters
  21. bias_initializer='zeros', # initialisation of bias
  22. kernel_regularizer=None, #
  23. bias_regularizer=None, #
  24. activity_regularizer=None, #
  25. kernel_constraint=None, #
  26. bias_constraint=None, #
  27. )
  28.  
  29. self.conv5 = Conv2D(32, # filters
  30. (3, 3), # Kernel size
  31. strides=(1, 1), # Stride
  32. padding='same', # Same refers to same padding as previous layer.
  33. data_format=None,
  34. # It should be defined if the dimensions are structured in non standard approach
  35. dilation_rate=(1, 1), # how dilated the picture is
  36. activation='relu', # Activation function
  37. use_bias=True, # Enable bias
  38. kernel_initializer='glorot_uniform', # initialiser of filters
  39. bias_initializer='zeros', # initialisation of bias
  40. kernel_regularizer=None, #
  41. bias_regularizer=None, #
  42. activity_regularizer=None, #
  43. kernel_constraint=None, #
  44. bias_constraint=None, #
  45. )
  46.  
  47. self.maxpool1 = MaxPooling2D(pool_size=(2, 2), # pool size
  48. strides=(2, 2), # stride size
  49. padding='same', # padding
  50. data_format=None) #
  51.  
  52. self.dropout2 = Dropout(rate=0.5,
  53. noise_shape=None,
  54. seed=None
  55. )
  56.  
  57. # Second convolutional layer
  58. self.conv2 = Conv2D(64, # filters
  59. (3, 3), # Kernel size
  60. strides=(1, 1), # Stride
  61. padding='same', # Same refers to same padding as previous layer.
  62. data_format=None,
  63. # It should be defined if the dimensions are structured in non standard approach
  64. dilation_rate=(1, 1), # how dilated the picture is
  65. activation='relu', # Activation function
  66. use_bias=True, # Enable bias
  67. kernel_initializer='glorot_uniform', # initialiser of filters
  68. bias_initializer='zeros', # initialisation of bias
  69. kernel_regularizer=None, #
  70. bias_regularizer=None, #
  71. activity_regularizer=None, #
  72. kernel_constraint=None, #
  73. bias_constraint=None, #
  74. )
  75.  
  76. self.dropout3 = Dropout(rate=0.5,
  77. noise_shape=None,
  78. seed=None
  79. )
  80.  
  81. # 3rd convolutional layer
  82. self.conv3 = Conv2D(128, # filters
  83. (3, 3), # Kernel size
  84. strides=(1, 1), # Stride
  85. padding='same', # Same refers to same padding as previous layer.
  86. data_format=None,
  87. # It should be defined if the dimensions are structured in non standard approach
  88. dilation_rate=(1, 1), # how dilated the picture is
  89. activation='relu', # Activation function
  90. use_bias=True, # Enable bias
  91. kernel_initializer='glorot_uniform', # initialiser of filters
  92. bias_initializer='zeros', # initialisation of bias
  93. kernel_regularizer=None, #
  94. bias_regularizer=None, #
  95. activity_regularizer=None, #
  96. kernel_constraint=None, #
  97. bias_constraint=None, #
  98. )
  99.  
  100. self.dropout4 = Dropout(rate=0.5,
  101. noise_shape=None,
  102. seed=None
  103. )
  104.  
  105. self.conv4 = Conv2D(256, # filters
  106. (3, 3), # Kernel size
  107. strides=(1, 1), # Stride
  108. padding='same', # Same refers to same padding as previous layer.
  109. data_format=None,
  110. # It should be defined if the dimensions are structured in non standard approach
  111. dilation_rate=(1, 1), # how dilated the picture is
  112. activation='relu', # Activation function
  113. use_bias=True, # Enable bias
  114. kernel_initializer='glorot_uniform', # initialiser of filters
  115. bias_initializer='zeros', # initialisation of bias
  116. kernel_regularizer=None, #
  117. bias_regularizer=None, #
  118. activity_regularizer=None, #
  119. kernel_constraint=None, #
  120. bias_constraint=None, #
  121. )
  122.  
  123.  
  124. self.flatten = Flatten()
  125.  
  126. self.dropout5 = Dropout(rate=0.85,
  127. noise_shape=None,
  128. seed=None
  129. )
  130.  
  131. # Dense is a fully connected layer
  132. self.d1 = Dense(256, # Amount of neurons
  133. activation='relu', # Activation function
  134. use_bias=True, # bias is enabled
  135. bias_initializer='zeros', # initialisation of bias
  136. bias_regularizer=None, # regularize biases
  137. activity_regularizer=None, #
  138. bias_constraint=None) #
  139.  
  140.  
  141. # Dense is a fully connected layer
  142. self.d2 = Dense(256, # Amount of neurons
  143. activation='relu', # Activation function
  144. use_bias=True, # bias is enabled
  145. bias_initializer='zeros', # initialisation of bias
  146. bias_regularizer=None, # regularize biases
  147. activity_regularizer=None, #
  148. bias_constraint=None) #
  149.  
  150. self.d3 = Dense(1, # Amount of neurons
  151. activation='sigmoid', # Activation function
  152. use_bias=True, # bias is enabled
  153. bias_initializer='zeros', # initialisation of bias
  154. bias_regularizer=None, # regularize biases
  155. activity_regularizer=None, #
  156. bias_constraint=None) #
  157.  
  158. # Call method should include all layers from model.
  159. def call(self, x):
  160. x = self.conv1(x)
  161. x = self.conv5(x)
  162. x = self.maxpool1(x)
  163. x = self.dropout2(x)
  164. x = self.conv2(x)
  165. # x = self.conv2(x)
  166. x = self.maxpool1(x)
  167. x = self.dropout3(x)
  168. x = self.conv3(x)
  169. # x = self.conv3(x)
  170. x = self.maxpool1(x)
  171. x = self.dropout4(x)
  172. x = self.conv4(x)
  173. # x = self.conv4(x)
  174. x = self.maxpool1(x)
  175. x = self.dropout5(x)
  176. x = self.flatten(x)
  177. x = self.d1(x)
  178. x = self.d2(x)
  179. return self.d3(x)
  180.  
  181. def model(self):
  182. x = Input(shape=(299, 299, 1))
  183. return Model(inputs=[x], outputs=self.call(x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement