Created
January 31, 2016 23:58
-
-
Save dela3499/f26cf4553527d4510e2b to your computer and use it in GitHub Desktop.
Rewriting keras example
This file contains 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 import Convolution2D, ZeroPadding2D, MaxPooling2D | |
img_width, img_height = 128, 128 | |
# this will contain our generated images | |
input_img = K.placeholder((1, 3, img_width, img_height)) | |
# build the VGG16 network with our input_img as input | |
first_layer = ZeroPadding2D((1, 1), input_shape=(3, img_width, img_height)) | |
first_layer.input = input_img | |
model = Sequential() | |
model.add(first_layer) | |
model.add(Convolution2D(64, 3, 3, activation='relu', name='conv1_1')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(64, 3, 3, activation='relu', name='conv1_2')) | |
model.add(MaxPooling2D((2, 2), strides=(2, 2))) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(128, 3, 3, activation='relu', name='conv2_1')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(128, 3, 3, activation='relu', name='conv2_2')) | |
model.add(MaxPooling2D((2, 2), strides=(2, 2))) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(256, 3, 3, activation='relu', name='conv3_1')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(256, 3, 3, activation='relu', name='conv3_2')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(256, 3, 3, activation='relu', name='conv3_3')) | |
model.add(MaxPooling2D((2, 2), strides=(2, 2))) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv4_1')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv4_2')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv4_3')) | |
model.add(MaxPooling2D((2, 2), strides=(2, 2))) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_1')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_2')) | |
model.add(ZeroPadding2D((1, 1))) | |
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_3')) | |
model.add(MaxPooling2D((2, 2), strides=(2, 2))) | |
# get the symbolic outputs of each "key" layer (we gave them unique names). | |
layer_dict = dict([(layer.name, layer) for layer in model.layers]) |
This file contains 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 import Convolution2D, ZeroPadding2D, MaxPooling2D | |
img_width, img_height = 128, 128 | |
input_img = K.placeholder((1, 3, img_width, img_height)) | |
# build the VGG16 network with our input_img as input | |
first_layer = ZeroPadding2D((1, 1), input_shape=(3, img_width, img_height)) | |
first_layer.input = input_img | |
Z = ZeroPadding2D((1, 1))) | |
MP = MaxPooling2D((2, 2), strides=(2, 2))) | |
# The fundamental information here is really contained in the following specification. | |
# Create groups for each element of list, where element is net size: [64,128,256,512,512] | |
# Each group will have some number of pairs of convolutional and zero padding elements. For the groups above: [2,2,3,3,3] | |
# The first pair of the first group actually isn't a pair. Instead of starting with the usual Z, it has a slightly special Z. | |
# each Group ends with a max pooling element. | |
# get the symbolic outputs of each "key" layer (we gave them unique names). | |
layer_dict = dict([(layer.name, layer) for layer in model.layers]) | |
# #C1 = Convolution2D(64, 3, 3, activation='relu') | |
# N = [64,128,256,512,512] | |
# model = Sequential() | |
# model.add(first_layer) | |
# C1, Z, C1, MP | |
# Z, C2, Z, C2, MP | |
# Z, C3, Z, C3, Z, C3, MP | |
# Z, C4, Z, C4, Z, C4, MP | |
# Z, C5, Z, C5, Z, C5, MP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment