Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from keras.models import Sequential
- from keras.layers import Conv2D,MaxPooling2D,Dense,Flatten
- def createVGGmodel(CLASSES):
- """
- ===DESCRIPTION===
- ----------------------------------------------------
- | Function creates and return VGGNet-16 model |
- | proposed and created by : |
- | Karen Simonyan∗& Andrew Zisserman |
- | https://arxiv.org/pdf/1409.1556.pdf |
- ----------------------------------------------------
- ===INPUT===
- CLASSES - amount of classes that we want to calssify
- ===OUTPUT===
- model - VGGNet-16 model
- """
- IMAGE_INPUT = (224,224,3)
- VGGNet16 = Sequential()
- VGGNet16.add(Conv2D(64,(3,3), activation = "relu", padding = "same",name = "block1_conv1", input_shape = IMAGE_INPUT))
- VGGNet16.add(Conv2D(64,(3,3), activation = "relu", padding = "same", name = "block1_conv2"))
- VGGNet16.add(MaxPooling2D((2,2), strides = (2,2), name = "block1_pooling"))
- VGGNet16.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1'))
- VGGNet16.add(Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2'))
- VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block2_pooling'))
- VGGNet16.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1'))
- VGGNet16.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2'))
- VGGNet16.add(Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3'))
- VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block3_pooling'))
- VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1'))
- VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2'))
- VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3'))
- VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block4_pooling'))
- VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1'))
- VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2'))
- VGGNet16.add(Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3'))
- VGGNet16.add(MaxPooling2D((2, 2), strides=(2, 2), name='block5_pooling'))
- VGGNet16.add(Flatten())
- VGGNet16.add(Dense(2048, activation='relu', name='fc1')) #Decreased by 50%, because i dont want to predict 1000 classes
- VGGNet16.add(Dense(1024, activation='relu', name='fc2'))
- VGGNet16.add(Dense(CLASSES, activation='softmax', name='predictions'))
- VGGNet16.compile(optimizer = "rmsprop", loss = 'categorical_crossentropy', metrics=['acc'])
- return VGGNet16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement