Python keras.layers.MaxPool2D() Examples
The following are 30
code examples of keras.layers.MaxPool2D().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keras.layers
, or try the search function
.

Example #1
Source Project: lpr Author: fanghon File: finemapping_vertical.py License: Apache License 2.0 | 6 votes |
def gettest_model(): input = Input(shape=[16, 66, 3]) # change this shape to [None,None,3] to enable arbitraty shape input A = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input) B = Activation("relu", name='relu1')(A) C = MaxPool2D(pool_size=2)(B) x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(C) x = Activation("relu", name='relu2')(x) x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x) K = Activation("relu", name='relu3')(x) x = Flatten()(K) dense = Dense(2,name = "dense")(x) output = Activation("relu", name='relu4')(dense) x = Model([input], [output]) x.load_weights("./model/model12.h5") ok = Model([input], [dense]) for layer in ok.layers: print(layer) return ok
Example #2
Source Project: AnomalyDetectionUsingAutoencoder Author: otenim File: models.py License: MIT License | 6 votes |
def convolutional_autoencoder(): input_shape=(28,28,1) n_channels = input_shape[-1] model = Sequential() model.add(Conv2D(32, (3,3), activation='relu', padding='same', input_shape=input_shape)) model.add(MaxPool2D(padding='same')) model.add(Conv2D(16, (3,3), activation='relu', padding='same')) model.add(MaxPool2D(padding='same')) model.add(Conv2D(8, (3,3), activation='relu', padding='same')) model.add(UpSampling2D()) model.add(Conv2D(16, (3,3), activation='relu', padding='same')) model.add(UpSampling2D()) model.add(Conv2D(32, (3,3), activation='relu', padding='same')) model.add(Conv2D(n_channels, (3,3), activation='sigmoid', padding='same')) return model
Example #3
Source Project: faceswap Author: deepfakes File: mtcnn.py License: GNU General Public License v3.0 | 6 votes |
def model_definition(): """ Keras RNetwork for MTCNN """ input_ = Input(shape=(24, 24, 3)) var_x = Conv2D(28, (3, 3), strides=1, padding='valid', name='conv1')(input_) var_x = PReLU(shared_axes=[1, 2], name='prelu1')(var_x) var_x = MaxPool2D(pool_size=3, strides=2, padding='same')(var_x) var_x = Conv2D(48, (3, 3), strides=1, padding='valid', name='conv2')(var_x) var_x = PReLU(shared_axes=[1, 2], name='prelu2')(var_x) var_x = MaxPool2D(pool_size=3, strides=2)(var_x) var_x = Conv2D(64, (2, 2), strides=1, padding='valid', name='conv3')(var_x) var_x = PReLU(shared_axes=[1, 2], name='prelu3')(var_x) var_x = Permute((3, 2, 1))(var_x) var_x = Flatten()(var_x) var_x = Dense(128, name='conv4')(var_x) var_x = PReLU(name='prelu4')(var_x) classifier = Dense(2, activation='softmax', name='conv5-1')(var_x) bbox_regress = Dense(4, name='conv5-2')(var_x) return [input_], [classifier, bbox_regress]
Example #4
Source Project: faceswap Author: deepfakes File: mtcnn.py License: GNU General Public License v3.0 | 6 votes |
def model_definition(): """ Keras ONetwork for MTCNN """ input_ = Input(shape=(48, 48, 3)) var_x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv1')(input_) var_x = PReLU(shared_axes=[1, 2], name='prelu1')(var_x) var_x = MaxPool2D(pool_size=3, strides=2, padding='same')(var_x) var_x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv2')(var_x) var_x = PReLU(shared_axes=[1, 2], name='prelu2')(var_x) var_x = MaxPool2D(pool_size=3, strides=2)(var_x) var_x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv3')(var_x) var_x = PReLU(shared_axes=[1, 2], name='prelu3')(var_x) var_x = MaxPool2D(pool_size=2)(var_x) var_x = Conv2D(128, (2, 2), strides=1, padding='valid', name='conv4')(var_x) var_x = PReLU(shared_axes=[1, 2], name='prelu4')(var_x) var_x = Permute((3, 2, 1))(var_x) var_x = Flatten()(var_x) var_x = Dense(256, name='conv5')(var_x) var_x = PReLU(name='prelu5')(var_x) classifier = Dense(2, activation='softmax', name='conv6-1')(var_x) bbox_regress = Dense(4, name='conv6-2')(var_x) landmark_regress = Dense(10, name='conv6-3')(var_x) return [input_], [classifier, bbox_regress, landmark_regress]
Example #5
Source Project: SmooFaceEngine Author: wotchin File: mtcnn_model.py License: Apache License 2.0 | 6 votes |
def create_Kao_Onet( weight_path = 'model48.h5'): input = Input(shape = [48,48,3]) x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1,2],name='prelu1')(x) x = MaxPool2D(pool_size=3, strides=2, padding='same')(x) x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1,2],name='prelu2')(x) x = MaxPool2D(pool_size=3, strides=2)(x) x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1,2],name='prelu3')(x) x = MaxPool2D(pool_size=2)(x) x = Conv2D(128, (2, 2), strides=1, padding='valid', name='conv4')(x) x = PReLU(shared_axes=[1,2],name='prelu4')(x) x = Permute((3,2,1))(x) x = Flatten()(x) x = Dense(256, name='conv5') (x) x = PReLU(name='prelu5')(x) classifier = Dense(2, activation='softmax',name='conv6-1')(x) bbox_regress = Dense(4,name='conv6-2')(x) landmark_regress = Dense(10,name='conv6-3')(x) model = Model([input], [classifier, bbox_regress, landmark_regress]) model.load_weights(weight_path, by_name=True) return model
Example #6
Source Project: SmooFaceEngine Author: wotchin File: mtcnn_model.py License: Apache License 2.0 | 6 votes |
def create_Kao_Rnet (weight_path = 'model24.h5'): input = Input(shape=[24, 24, 3]) # change this shape to [None,None,3] to enable arbitraty shape input x = Conv2D(28, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1, 2], name='prelu1')(x) x = MaxPool2D(pool_size=3,strides=2, padding='same')(x) x = Conv2D(48, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1, 2], name='prelu2')(x) x = MaxPool2D(pool_size=3, strides=2)(x) x = Conv2D(64, (2, 2), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1, 2], name='prelu3')(x) x = Permute((3, 2, 1))(x) x = Flatten()(x) x = Dense(128, name='conv4')(x) x = PReLU( name='prelu4')(x) classifier = Dense(2, activation='softmax', name='conv5-1')(x) bbox_regress = Dense(4, name='conv5-2')(x) model = Model([input], [classifier, bbox_regress]) model.load_weights(weight_path, by_name=True) return model
Example #7
Source Project: landslide Author: rknaebel File: networks.py License: MIT License | 6 votes |
def get_convnet_landslide_all(args) -> Model: input_shape = (args.area_size, args.area_size, 14) model = Sequential() model.add(Conv2D(8, 3, 3, input_shape=input_shape, init='normal')) model.add(Activation('relu')) model.add(Conv2D(8, 3, 3, init='normal')) model.add(Activation('relu')) model.add(MaxPool2D((1, 1), strides=(1, 1))) model.add(Dropout(0.25)) model.add(Flatten(name="flatten")) # model.add(Dense(512, activation='relu', name='dense', init='normal')) model.add(Dropout(0.25)) model.add(Dense(1, name='last_layer')) model.add(Activation('sigmoid')) return model
Example #8
Source Project: landslide Author: rknaebel File: networks.py License: MIT License | 6 votes |
def get_model_1(args): model = Sequential() model.add(Conv2D(32, (5, 5), input_shape=(args.area_size, args.area_size, 14))) model.add(Activation('relu')) model.add(Conv2D(16, (3, 3))) model.add(Activation('relu')) model.add(MaxPool2D((1, 1), strides=(1, 1))) model.add(Dropout(0.25)) # model.add(AvgPool2D((3, 3), strides=(1, 1))) model.add(Flatten(name="flatten")) # model.add(Dense(1, name='last_layer')) model.add(Activation('sigmoid')) return model
Example #9
Source Project: landslide Author: rknaebel File: networks.py License: MIT License | 6 votes |
def get_model_cifar(args): model = Sequential() model.add(Conv2D(32, (3, 3), padding='same', input_shape=(args.area_size, args.area_size, 14))) model.add(Activation('relu')) model.add(Conv2D(32, (3, 3))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Conv2D(64, (3, 3), padding='same')) model.add(Activation('relu')) model.add(Conv2D(64, (3, 3))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(2, 2))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(512)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(1)) model.add(Activation('sigmoid')) return model
Example #10
Source Project: mtcnn-keras Author: bubbliiiing File: mtcnn.py License: MIT License | 6 votes |
def create_Pnet(weight_path): input = Input(shape=[None, None, 3]) x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1,2],name='PReLU1')(x) x = MaxPool2D(pool_size=2)(x) x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1,2],name='PReLU2')(x) x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1,2],name='PReLU3')(x) classifier = Conv2D(2, (1, 1), activation='softmax', name='conv4-1')(x) # 无激活函数,线性。 bbox_regress = Conv2D(4, (1, 1), name='conv4-2')(x) model = Model([input], [classifier, bbox_regress]) model.load_weights(weight_path, by_name=True) return model #-----------------------------# # mtcnn的第二段 # 精修框 #-----------------------------#
Example #11
Source Project: keras-mtcnn Author: xiangrufan File: MTCNN.py License: MIT License | 6 votes |
def create_Kao_Onet( weight_path = 'model48.h5'): input = Input(shape = [48,48,3]) x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1,2],name='prelu1')(x) x = MaxPool2D(pool_size=3, strides=2, padding='same')(x) x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1,2],name='prelu2')(x) x = MaxPool2D(pool_size=3, strides=2)(x) x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1,2],name='prelu3')(x) x = MaxPool2D(pool_size=2)(x) x = Conv2D(128, (2, 2), strides=1, padding='valid', name='conv4')(x) x = PReLU(shared_axes=[1,2],name='prelu4')(x) x = Permute((3,2,1))(x) x = Flatten()(x) x = Dense(256, name='conv5') (x) x = PReLU(name='prelu5')(x) classifier = Dense(2, activation='softmax',name='conv6-1')(x) bbox_regress = Dense(4,name='conv6-2')(x) landmark_regress = Dense(10,name='conv6-3')(x) model = Model([input], [classifier, bbox_regress, landmark_regress]) model.load_weights(weight_path, by_name=True) return model
Example #12
Source Project: keras-mtcnn Author: xiangrufan File: MTCNN.py License: MIT License | 6 votes |
def create_Kao_Rnet (weight_path = 'model24.h5'): input = Input(shape=[24, 24, 3]) # change this shape to [None,None,3] to enable arbitraty shape input x = Conv2D(28, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1, 2], name='prelu1')(x) x = MaxPool2D(pool_size=3,strides=2, padding='same')(x) x = Conv2D(48, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1, 2], name='prelu2')(x) x = MaxPool2D(pool_size=3, strides=2)(x) x = Conv2D(64, (2, 2), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1, 2], name='prelu3')(x) x = Permute((3, 2, 1))(x) x = Flatten()(x) x = Dense(128, name='conv4')(x) x = PReLU( name='prelu4')(x) classifier = Dense(2, activation='softmax', name='conv5-1')(x) bbox_regress = Dense(4, name='conv5-2')(x) model = Model([input], [classifier, bbox_regress]) model.load_weights(weight_path, by_name=True) return model
Example #13
Source Project: Face-skin-hair-segmentaiton-and-skin-color-evaluation Author: JACKYLUO1991 File: lednet.py License: Apache License 2.0 | 5 votes |
def down_sample(self, x, filters): x_filters = int(x.shape[-1]) x_conv = layers.Conv2D(filters - x_filters, kernel_size=3, strides=(2, 2), padding='same')(x) x_pool = layers.MaxPool2D()(x) x = layers.concatenate([x_conv, x_pool], axis=-1) x = layers.BatchNormalization()(x) x = layers.Activation('relu')(x) return x
Example #14
Source Project: ai-platform Author: produvia File: yolov3_weights_to_keras.py License: MIT License | 5 votes |
def _SPP_block(inp, kernels, strides): pools = [MaxPool2D(pool_size = pool_size, strides = stride, padding = 'same')(inp) \ for pool_size, stride in zip(kernels, strides)] pools = [inp] + pools return concatenate(pools) #Downsampling block is common to all YOLO-v3 models and are unaffected by the SPP or fully connected blocks or the number of labes
Example #15
Source Project: keras-face-recognition Author: bubbliiiing File: mtcnn.py License: MIT License | 5 votes |
def create_Pnet(weight_path): # h,w input = Input(shape=[None, None, 3]) # h,w,3 -> h/2,w/2,10 x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1,2],name='PReLU1')(x) x = MaxPool2D(pool_size=2)(x) # h/2,w/2,10 -> h/2,w/2,16 x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1,2],name='PReLU2')(x) # h/2,w/2,32 x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1,2],name='PReLU3')(x) # h/2, w/2, 2 classifier = Conv2D(2, (1, 1), activation='softmax', name='conv4-1')(x) # 无激活函数,线性。 # h/2, w/2, 4 bbox_regress = Conv2D(4, (1, 1), name='conv4-2')(x) model = Model([input], [classifier, bbox_regress]) model.load_weights(weight_path, by_name=True) return model #-----------------------------# # mtcnn的第二段 # 精修框 #-----------------------------#
Example #16
Source Project: keras-face-recognition Author: bubbliiiing File: mtcnn.py License: MIT License | 5 votes |
def create_Rnet(weight_path): input = Input(shape=[24, 24, 3]) # 24,24,3 -> 11,11,28 x = Conv2D(28, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1, 2], name='prelu1')(x) x = MaxPool2D(pool_size=3,strides=2, padding='same')(x) # 11,11,28 -> 4,4,48 x = Conv2D(48, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1, 2], name='prelu2')(x) x = MaxPool2D(pool_size=3, strides=2)(x) # 4,4,48 -> 3,3,64 x = Conv2D(64, (2, 2), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1, 2], name='prelu3')(x) # 3,3,64 -> 64,3,3 x = Permute((3, 2, 1))(x) x = Flatten()(x) # 576 -> 128 x = Dense(128, name='conv4')(x) x = PReLU( name='prelu4')(x) # 128 -> 2 128 -> 4 classifier = Dense(2, activation='softmax', name='conv5-1')(x) bbox_regress = Dense(4, name='conv5-2')(x) model = Model([input], [classifier, bbox_regress]) model.load_weights(weight_path, by_name=True) return model #-----------------------------# # mtcnn的第三段 # 精修框并获得五个点 #-----------------------------#
Example #17
Source Project: keras-face-recognition Author: bubbliiiing File: mtcnn.py License: MIT License | 5 votes |
def create_Onet(weight_path): input = Input(shape = [48,48,3]) # 48,48,3 -> 23,23,32 x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1,2],name='prelu1')(x) x = MaxPool2D(pool_size=3, strides=2, padding='same')(x) # 23,23,32 -> 10,10,64 x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1,2],name='prelu2')(x) x = MaxPool2D(pool_size=3, strides=2)(x) # 8,8,64 -> 4,4,64 x = Conv2D(64, (3, 3), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1,2],name='prelu3')(x) x = MaxPool2D(pool_size=2)(x) # 4,4,64 -> 3,3,128 x = Conv2D(128, (2, 2), strides=1, padding='valid', name='conv4')(x) x = PReLU(shared_axes=[1,2],name='prelu4')(x) # 3,3,128 -> 128,3,3 x = Permute((3,2,1))(x) # 1152 -> 256 x = Flatten()(x) x = Dense(256, name='conv5') (x) x = PReLU(name='prelu5')(x) # 鉴别 # 256 -> 2 256 -> 4 256 -> 10 classifier = Dense(2, activation='softmax',name='conv6-1')(x) bbox_regress = Dense(4,name='conv6-2')(x) landmark_regress = Dense(10,name='conv6-3')(x) model = Model([input], [classifier, bbox_regress, landmark_regress]) model.load_weights(weight_path, by_name=True) return model
Example #18
Source Project: ImageAI Author: OlafenwaMoses File: models.py License: MIT License | 5 votes |
def tiny_yolo_main(input, num_anchors, num_classes): network_1 = NetworkConv2D_BN_Leaky(input=input, channels=16, kernel_size=(3,3) ) network_1 = MaxPool2D(pool_size=(2,2), strides=(2,2), padding="same")(network_1) network_1 = NetworkConv2D_BN_Leaky(input=network_1, channels=32, kernel_size=(3, 3)) network_1 = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding="same")(network_1) network_1 = NetworkConv2D_BN_Leaky(input=network_1, channels=64, kernel_size=(3, 3)) network_1 = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding="same")(network_1) network_1 = NetworkConv2D_BN_Leaky(input=network_1, channels=128, kernel_size=(3, 3)) network_1 = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding="same")(network_1) network_1 = NetworkConv2D_BN_Leaky(input=network_1, channels=256, kernel_size=(3, 3)) network_2 = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding="same")(network_1) network_2 = NetworkConv2D_BN_Leaky(input=network_2, channels=512, kernel_size=(3, 3)) network_2 = MaxPool2D(pool_size=(2, 2), strides=(1, 1), padding="same")(network_2) network_2 = NetworkConv2D_BN_Leaky(input=network_2, channels=1024, kernel_size=(3, 3)) network_2 = NetworkConv2D_BN_Leaky(input=network_2, channels=256, kernel_size=(1, 1)) network_3 = NetworkConv2D_BN_Leaky(input=network_2, channels=512, kernel_size=(3, 3)) network_3 = Conv2D(num_anchors * (num_classes + 5), kernel_size=(1,1))(network_3) network_2 = NetworkConv2D_BN_Leaky(input=network_2, channels=128, kernel_size=(1, 1)) network_2 = UpSampling2D(2)(network_2) network_4 = Concatenate()([network_2, network_1]) network_4 = NetworkConv2D_BN_Leaky(input=network_4, channels=256, kernel_size=(3, 3)) network_4 = Conv2D(num_anchors * (num_classes + 5), kernel_size=(1,1))(network_4) return Model(input, [network_3, network_4])
Example #19
Source Project: lpr Author: fanghon File: typeDistinguish.py License: Apache License 2.0 | 5 votes |
def Getmodel_tensorflow(nb_classes): # nb_classes = len(charset) img_rows, img_cols = 9, 34 # number of convolutional filters to use nb_filters = 32 # size of pooling area for max pooling nb_pool = 2 # convolution kernel size nb_conv = 3 # x = np.load('x.npy') # y = np_utils.to_categorical(range(3062)*45*5*2, nb_classes) # weight = ((type_class - np.arange(type_class)) / type_class + 1) ** 3 # weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先 model = Sequential() model.add(Conv2D(16, (5, 5),input_shape=(img_rows, img_cols,3))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Flatten()) model.add(Dense(64)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) return model
Example #20
Source Project: lpr Author: fanghon File: finemapping_vertical.py License: Apache License 2.0 | 5 votes |
def getModel(): input = Input(shape=[16, 66, 3]) # change this shape to [None,None,3] to enable arbitraty shape input x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input) x = Activation("relu", name='relu1')(x) x = MaxPool2D(pool_size=2)(x) x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(x) x = Activation("relu", name='relu2')(x) x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x) x = Activation("relu", name='relu3')(x) x = Flatten()(x) output = Dense(2,name = "dense")(x) output = Activation("relu", name='relu4')(output) model = Model([input], [output]) return model
Example #21
Source Project: lpr Author: fanghon File: segmentation.py License: Apache License 2.0 | 5 votes |
def Getmodel_tensorflow(nb_classes): # nb_classes = len(charset) img_rows, img_cols = 23, 23 # number of convolutional filters to use nb_filters = 16 # size of pooling area for max pooling nb_pool = 2 # convolution kernel size nb_conv = 3 # x = np.load('x.npy') # y = np_utils.to_categorical(range(3062)*45*5*2, nb_classes) # weight = ((type_class - np.arange(type_class)) / type_class + 1) ** 3 # weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先 model = Sequential() model.add(Conv2D(nb_filters, (nb_conv, nb_conv),input_shape=(img_rows, img_cols,1))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Conv2D(nb_filters, (nb_conv, nb_conv))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Flatten()) model.add(Dense(256)) model.add(Dropout(0.5)) model.add(Activation('relu')) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) return model
Example #22
Source Project: lpr Author: fanghon File: segmentation.py License: Apache License 2.0 | 5 votes |
def Getmodel_tensorflow_light(nb_classes): # nb_classes = len(charset) img_rows, img_cols = 23, 23 # number of convolutional filters to use nb_filters = 8 # size of pooling area for max pooling nb_pool = 2 # convolution kernel size nb_conv = 3 # x = np.load('x.npy') # y = np_utils.to_categorical(range(3062)*45*5*2, nb_classes) # weight = ((type_class - np.arange(type_class)) / type_class + 1) ** 3 # weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先 model = Sequential() model.add(Conv2D(nb_filters, (nb_conv, nb_conv),input_shape=(img_rows, img_cols, 1))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Conv2D(nb_filters, (nb_conv * 2, nb_conv * 2))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Flatten()) model.add(Dense(32)) # model.add(Dropout(0.25)) model.add(Activation('relu')) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) return model
Example #23
Source Project: lpr Author: fanghon File: recognizer.py License: Apache License 2.0 | 5 votes |
def Getmodel_ch(nb_classes): # nb_classes = len(charset) img_rows, img_cols = 23, 23 # number of convolutional filters to use nb_filters = 32 # size of pooling area for max pooling nb_pool = 2 # convolution kernel size nb_conv = 3 # x = np.load('x.npy') # y = np_utils.to_categorical(range(3062)*45*5*2, nb_classes) # weight = ((type_class - np.arange(type_class)) / type_class + 1) ** 3 # weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先 model = Sequential() model.add(Conv2D(32, (5, 5),input_shape=(img_rows, img_cols,1))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Dropout(0.25)) model.add(Conv2D(32, (3, 3))) model.add(Activation('relu')) model.add(MaxPool2D(pool_size=(nb_pool, nb_pool))) model.add(Dropout(0.25)) model.add(Conv2D(512, (3, 3))) # model.add(Activation('relu')) # model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool))) # model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(756)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) return model
Example #24
Source Project: IdenProf Author: OlafenwaMoses File: idenprof.py License: MIT License | 5 votes |
def ResNet50(input_shape, num_classes=10): input_object = Input(shape=input_shape) layers = [3, 4, 6, 3] channel_depths = [256, 512, 1024, 2048] output = Conv2D(64, kernel_size=7, strides=2, padding="same", kernel_initializer="he_normal")(input_object) output = BatchNormalization()(output) output = Activation("relu")(output) output = MaxPool2D(pool_size=(3, 3), strides=(2, 2))(output) output = resnet_first_block_first_module(output, channel_depths[0]) for i in range(4): channel_depth = channel_depths[i] num_layers = layers[i] strided_pool_first = True if (i == 0): strided_pool_first = False num_layers = num_layers - 1 output = resnet_block(output, channel_depth=channel_depth, num_layers=num_layers, strided_pool_first=strided_pool_first) output = GlobalAvgPool2D()(output) output = Dense(num_classes)(output) output = Activation("softmax")(output) model = Model(inputs=input_object, outputs=output) return model
Example #25
Source Project: Keras-TextClassification Author: yongzhuo File: graph.py License: MIT License | 5 votes |
def create_model(self, hyper_parameters): """ 构建神经网络 :param hyper_parameters:json, hyper parameters of network :return: tensor, moedl """ super().create_model(hyper_parameters) embedding = self.word_embedding.output embedding_reshape = Reshape((self.len_max, self.embed_size, 1))(embedding) # 提取n-gram特征和最大池化, 一般不用平均池化 conv_pools = [] for filter in self.filters: conv = Conv2D(filters = self.filters_num, kernel_size = (filter, self.embed_size), padding = 'valid', kernel_initializer = 'normal', activation = 'relu', )(embedding_reshape) pooled = MaxPool2D(pool_size = (self.len_max - filter + 1, 1), strides = (1, 1), padding = 'valid', )(conv) conv_pools.append(pooled) # 拼接 x = Concatenate(axis=-1)(conv_pools) x = Flatten()(x) x = Dropout(self.dropout)(x) output = Dense(units=self.label, activation=self.activate_classify)(x) self.model = Model(inputs=self.word_embedding.input, outputs=output) self.model.summary(120)
Example #26
Source Project: deep_learning Author: jarvisqi File: licenseplate.py License: MIT License | 5 votes |
def main(): input_tensor = Input((72, 272, 3)) x = input_tensor print("build model") x = Conv2D(32, kernel_size=(3, 3), activation='relu')(x) x = Conv2D(32, kernel_size=(3, 3), activation='relu')(x) x = MaxPool2D(pool_size=(2, 2))(x) x = Conv2D(64, kernel_size=(3, 3), activation='relu')(x) x = Conv2D(64, kernel_size=(3, 3), activation='relu')(x) x = MaxPool2D(pool_size=(2, 2))(x) x = Dropout(0.3)(x) x = Conv2D(128, kernel_size=(3, 3), activation='relu')(x) x = Conv2D(128, kernel_size=(3, 3), activation='relu')(x) x = MaxPool2D(pool_size=(2, 2))(x) x = Dropout(0.3)(x) x = Flatten()(x) x = Dropout(0.5)(x) n_class = len(chars) x = [Dense(n_class, activation='softmax', name='c{0}'.format(i + 1))(x) for i in range(7)] model = Model(inputs=input_tensor, outputs=x) print("compile model") adam = Adam(lr=0.001) model.compile(loss='categorical_crossentropy', optimizer=adam, metrics=['accuracy']) # display plot_model(model,to_file='./models/licenseplate_model.png') # training print("training model") best_model = ModelCheckpoint("./models/licenseplate.h5", monitor='val_loss', verbose=0, save_best_only=True) model.fit_generator(gen_plate(), steps_per_epoch=2000, epochs=8, validation_data=gen_plate(), validation_steps=1280, callbacks=[best_model])
Example #27
Source Project: nni Author: microsoft File: layers.py License: MIT License | 5 votes |
def to_real_keras_layer(layer): """ Real keras layer. """ from keras import layers if is_layer(layer, "Dense"): return layers.Dense(layer.units, input_shape=(layer.input_units,)) if is_layer(layer, "Conv"): return layers.Conv2D( layer.filters, layer.kernel_size, input_shape=layer.input.shape, padding="same", ) # padding if is_layer(layer, "Pooling"): return layers.MaxPool2D(2) if is_layer(layer, "BatchNormalization"): return layers.BatchNormalization(input_shape=layer.input.shape) if is_layer(layer, "Concatenate"): return layers.Concatenate() if is_layer(layer, "Add"): return layers.Add() if is_layer(layer, "Dropout"): return keras_dropout(layer, layer.rate) if is_layer(layer, "ReLU"): return layers.Activation("relu") if is_layer(layer, "Softmax"): return layers.Activation("softmax") if is_layer(layer, "Flatten"): return layers.Flatten() if is_layer(layer, "GlobalAveragePooling"): return layers.GlobalAveragePooling2D() return None # note: this is not written by original author, feel free to modify if you think it's incorrect
Example #28
Source Project: faceswap Author: deepfakes File: mtcnn.py License: GNU General Public License v3.0 | 5 votes |
def model_definition(): """ Keras PNetwork for MTCNN """ input_ = Input(shape=(None, None, 3)) var_x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input_) var_x = PReLU(shared_axes=[1, 2], name='PReLU1')(var_x) var_x = MaxPool2D(pool_size=2)(var_x) var_x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(var_x) var_x = PReLU(shared_axes=[1, 2], name='PReLU2')(var_x) var_x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(var_x) var_x = PReLU(shared_axes=[1, 2], name='PReLU3')(var_x) classifier = Conv2D(2, (1, 1), activation='softmax', name='conv4-1')(var_x) bbox_regress = Conv2D(4, (1, 1), name='conv4-2')(var_x) return [input_], [classifier, bbox_regress]
Example #29
Source Project: SmooFaceEngine Author: wotchin File: mtcnn_model.py License: Apache License 2.0 | 5 votes |
def create_Kao_Pnet( weight_path = 'model12old.h5'): input = Input(shape=[None, None, 3]) x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input) x = PReLU(shared_axes=[1,2],name='PReLU1')(x) x = MaxPool2D(pool_size=2)(x) x = Conv2D(16, (3, 3), strides=1, padding='valid', name='conv2')(x) x = PReLU(shared_axes=[1,2],name='PReLU2')(x) x = Conv2D(32, (3, 3), strides=1, padding='valid', name='conv3')(x) x = PReLU(shared_axes=[1,2],name='PReLU3')(x) classifier = Conv2D(2, (1, 1), activation='softmax', name='conv4-1')(x) bbox_regress = Conv2D(4, (1, 1), name='conv4-2')(x) model = Model([input], [classifier, bbox_regress]) model.load_weights(weight_path, by_name=True) return model
Example #30
Source Project: landslide Author: rknaebel File: networks.py License: MIT License | 5 votes |
def get_model_2(args): model = Sequential() model.add(Conv2D(32, (5, 1), padding="same", input_shape=(args.area_size, args.area_size, 14))) model.add(Activation('relu')) model.add(Conv2D(32, (1, 5), padding="same")) model.add(Maxout()) model.add(Conv2D(32, (5, 1), padding="same")) model.add(Activation('relu')) model.add(Conv2D(32, (1, 5), padding="same")) model.add(Maxout()) model.add(MaxPool2D(pool_size=(2, 2))) model.add(Dropout(0.25)) # model.add(Conv2D(16, (3, 1), padding="same")) model.add(Activation('relu')) model.add(Conv2D(16, (1, 3), padding="same")) model.add(Maxout()) model.add(Conv2D(16, (3, 1), padding="same")) model.add(Activation('relu')) model.add(Conv2D(16, (1, 3), padding="same")) model.add(Maxout()) model.add(MaxPool2D(pool_size=(2, 2))) model.add(Dropout(0.25)) # model.add(AvgPool2D((3, 3), strides=(1, 1))) model.add(Flatten(name="flatten")) # model.add(Dense(1, name='last_layer')) model.add(Activation('sigmoid')) return model