Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. import tensorflow as tf
  2. from tensorflow.keras import Model
  3. from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, ZeroPadding2D, Input, Dropout
  4.  
  5.  
  6. class Model_Version_1_01(tf.keras.Model):
  7. def __init__(self):
  8. super(Model_Version_1_01, self).__init__()
  9.  
  10. # first convolutional layer
  11. self.conv1 = Conv2D(16, # 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. self.dropout20 = Dropout(rate=0.2,
  29. noise_shape=None,
  30. seed=None,
  31. )
  32. # Second convolutional layer
  33. self.conv2 = Conv2D(32, # filters
  34. (3, 3), # Kernel size
  35. strides=(1, 1), # Stride
  36. padding='same', # Same refers to same padding as previous layer.
  37. data_format=None,
  38. # It should be defined if the dimensions are structured in non standard approach
  39. dilation_rate=(1, 1), # how dilated the picture is
  40. activation='relu', # Activation function
  41. use_bias=True, # Enable bias
  42. kernel_initializer='glorot_uniform', # initialiser of filters
  43. bias_initializer='zeros', # initialisation of bias
  44. kernel_regularizer=None, #
  45. bias_regularizer=None, #
  46. activity_regularizer=None, #
  47. kernel_constraint=None, #
  48. bias_constraint=None, #
  49. )
  50.  
  51. # 3rd convolutional layer
  52. self.conv3 = Conv2D(64, # filters
  53. (3, 3), # Kernel size
  54. strides=(1, 1), # Stride
  55. padding='same', # Same refers to same padding as previous layer.
  56. data_format=None,
  57. # It should be defined if the dimensions are structured in non standard approach
  58. dilation_rate=(1, 1), # how dilated the picture is
  59. activation='relu', # Activation function
  60. use_bias=True, # Enable bias
  61. kernel_initializer='glorot_uniform', # initialiser of filters
  62. bias_initializer='zeros', # initialisation of bias
  63. kernel_regularizer=None, #
  64. bias_regularizer=None, #
  65. activity_regularizer=None, #
  66. kernel_constraint=None, #
  67. bias_constraint=None, #
  68. )
  69.  
  70. self.maxpool2 = MaxPooling2D(pool_size=(2, 2), # pool size
  71. strides=(2, 2), # stride size
  72. padding='same', # padding
  73. data_format=None) #
  74.  
  75. self.flatten = Flatten()
  76.  
  77. # Dense is a fully connected layer
  78. self.d1 = Dense(512, # Amount of neurons
  79. activation='relu', # Activation function
  80. use_bias=True, # bias is enabled
  81. bias_initializer='zeros', # initialisation of bias
  82. bias_regularizer=None, # regularize biases
  83. activity_regularizer=None, #
  84. bias_constraint=None) #
  85.  
  86. # Dense is a fully connected layer
  87. self.d2 = Dense(512, # Amount of neurons
  88. activation='relu', # Activation function
  89. use_bias=True, # bias is enabled
  90. bias_initializer='zeros', # initialisation of bias
  91. bias_regularizer=None, # regularize biases
  92. activity_regularizer=None, #
  93. bias_constraint=None) #
  94.  
  95. self.d3 = Dense(5, # Amount of neurons
  96. activation='sigmoid', # Activation function
  97. use_bias=True, # bias is enabled
  98. bias_initializer='zeros', # initialisation of bias
  99. bias_regularizer=None, # regularize biases
  100. activity_regularizer=None, #
  101. bias_constraint=None) #
  102.  
  103. # Call method should include all layers from model.
  104. def call(self, x):
  105. x = self.conv1(x)
  106. x = self.dropout20(x)
  107. x = self.maxpool2(x)
  108. x = self.conv2(x)
  109. x = self.dropout20(x)
  110. x = self.maxpool2(x)
  111. x = self.conv3(x)
  112. x = self.dropout20(x)
  113. x = self.maxpool2(x)
  114. x = self.flatten(x)
  115. x = self.d1(x)
  116. x = self.d2(x)
  117. return self.d3(x)
  118.  
  119. def model(self):
  120. x = Input(shape=(299, 299, 1))
  121. return Model(inputs=[x], outputs=self.call(x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement