Advertisement
Guest User

asdas

a guest
Sep 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. import numpy as np
  2. from keras.models import Sequential
  3. from keras.layers import Conv2D,MaxPooling2D,Dense,Flatten
  4.  
  5. def createVGGmodel(CLASSES):
  6. """
  7. ===DESCRIPTION===
  8. ----------------------------------------------------
  9. | Function creates and return VGGNet-16 model |
  10. | proposed and created by : |
  11. | Karen Simonyan∗& Andrew Zisserman |
  12. | https://arxiv.org/pdf/1409.1556.pdf |
  13. ----------------------------------------------------
  14. ===INPUT===
  15. CLASSES - amount of classes that we want to calssify
  16.  
  17. ===OUTPUT===
  18. model - VGGNet-16 model
  19.  
  20. """
  21. IMAGE_INPUT = (224,224,3)
  22.  
  23. VGGNet16 = Sequential()
  24. VGGNet16.add(Conv2D(64,(3,3), activation = "relu", padding = "same",name = "block1_conv1", input_shape = IMAGE_INPUT))
  25. VGGNet16.add(Conv2D(64,(3,3), activation = "relu", padding = "same", name = "block1_conv2"))
  26. VGGNet16.add(MaxPooling2D((2,2), strides = (2,2), name = "block1_pooling"))
  27.  
  28. VGGNet16.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1'))
  29. VGGNet16.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2'))
  30. VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block2_pooling'))
  31.  
  32. VGGNet16.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1'))
  33. VGGNet16.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2'))
  34. VGGNet16.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3'))
  35. VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block3_pooling'))
  36.  
  37. VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1'))
  38. VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2'))
  39. VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3'))
  40. VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block4_pooling'))
  41.  
  42. VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1'))
  43. VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2'))
  44. VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3'))
  45. VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block5_pooling'))
  46.  
  47. VGGNet16.add(Flatten())
  48. VGGNet16.add(Dense(2048, activation='relu', name='fc1')) #Decreased by 50%, because i dont want to predict 1000 classes
  49. VGGNet16.add(Dense(1024, activation='relu', name='fc2'))
  50. VGGNet16.add(Dense(CLASSES, activation='softmax', name='predictions'))
  51. VGGNet16.compile(optimizer = "rmsprop", loss = 'categorical_crossentropy', metrics=['acc'])
  52.  
  53. return VGGNet16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement