Created
September 3, 2017 08:28
-
-
Save Thimira/f711008a8c7ede28815388954b74591b to your computer and use it in GitHub Desktop.
The VGG16 Deep Learning model created using the Sequential model of Keras v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Sequential | |
from keras.layers.core import Flatten, Dense, Dropout | |
from keras.layers.convolutional import Conv2D, MaxPooling2D, ZeroPadding2D | |
from keras.optimizers import SGD | |
import numpy as np | |
def VGG_16(weights_path=None): | |
input_shape=(224,224,3) | |
model = Sequential() | |
model.add(ZeroPadding2D((1,1),input_shape=input_shape)) | |
model.add(Conv2D(64, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(64, (3, 3), activation='relu')) | |
model.add(MaxPooling2D((2,2), strides=(2,2))) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(128, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(128, (3, 3), activation='relu')) | |
model.add(MaxPooling2D((2,2), strides=(2,2))) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(256, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(256, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(256, (3, 3), activation='relu')) | |
model.add(MaxPooling2D((2,2), strides=(2,2))) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(512, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(512, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(512, (3, 3), activation='relu')) | |
model.add(MaxPooling2D((2,2), strides=(2,2))) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(512, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(512, (3, 3), activation='relu')) | |
model.add(ZeroPadding2D((1,1))) | |
model.add(Conv2D(512, (3, 3), activation='relu')) | |
model.add(MaxPooling2D((2,2), strides=(2,2))) | |
model.add(Flatten()) | |
model.add(Dense(4096, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(4096, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(1000, activation='softmax')) | |
if weights_path: | |
model.load_weights(weights_path) | |
return model | |
model = VGG_16() | |
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True) | |
model.compile(optimizer=sgd, loss='categorical_crossentropy') |
Hello, do you have any examples to train the VGG16 from scratch, ie with new dataset?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is part of the book Build Deeper: Deep Learning Beginners' Guide.
More details can be found at the Codes of Interest site.