Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def VGG16(weights_path=None):
model = Sequential()
model.add(ZeroPadding2D((1,1),input_shape=(224,224,3)))
model.add(Convolution2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1'))
model.add(Convolution2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2'))
model.add(MaxPooling2D((2,2), strides=(2,2), name='block1_pool'))
model.add(Convolution2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1'))
model.add(Convolution2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2'))
model.add(MaxPooling2D((2,2), strides=(2,2), name='block2_pool'))
model.add(Convolution2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1'))
model.add(Convolution2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2'))
model.add(Convolution2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3'))
model.add(MaxPooling2D((2,2), strides=(2,2), name='block3_pool'))
model.add(Convolution2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1'))
model.add(Convolution2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2'))
model.add(Convolution2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3'))
model.add(MaxPooling2D((2,2), strides=(2,2), name='block4_pool'))
model.add(Convolution2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1'))
model.add(Convolution2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2'))
model.add(Convolution2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3'))
model.add(MaxPooling2D((2,2), strides=(2,2), name='block5_pool'))
model.add(Flatten(name='flatten'))
model.add(Dense(4096, activation='relu', name='fully_connected_1'))
model.add(Dropout(0.5))
model.add(Dense(4096, activation='relu', name='fully_connected_2'))
model.add(Dropout(0.5))
model.add(Dense(1000, activation='softmax', name='predictions'))
if weights_path:
model.load_weights(weights_path)
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment