您当前的位置:首页 > IT编程 > Keras
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch |

自学教程:Python layers.ZeroPadding2D方法代码示例

51自学网 2020-12-01 11:08:50
  Keras
这篇教程Python layers.ZeroPadding2D方法代码示例写得很实用,希望能帮到您。

本文整理汇总了Python中keras.layers.ZeroPadding2D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.ZeroPadding2D方法的具体用法?Python layers.ZeroPadding2D怎么用?Python layers.ZeroPadding2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers的用法示例。

在下文中一共展示了layers.ZeroPadding2D方法的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _conv2d_same

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def _conv2d_same(x, filters, prefix, stride=1, kernel_size=3, rate=1):    # 计算padding的数量,hw是否需要收缩    if stride == 1:        return Conv2D(filters,                      (kernel_size, kernel_size),                      strides=(stride, stride),                      padding='same', use_bias=False,                      dilation_rate=(rate, rate),                      name=prefix)(x)    else:        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)        pad_total = kernel_size_effective - 1        pad_beg = pad_total // 2        pad_end = pad_total - pad_beg        x = ZeroPadding2D((pad_beg, pad_end))(x)        return Conv2D(filters,                      (kernel_size, kernel_size),                      strides=(stride, stride),                      padding='valid', use_bias=False,                      dilation_rate=(rate, rate),                      name=prefix)(x) 
开发者ID:bubbliiiing,项目名称:Semantic-Segmentation,代码行数:23,代码来源:Xception.py


示例2: _conv_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def _conv_block(inp, convs, skip=True):  x = inp  count = 0  len_convs = len(convs)  for conv in convs:    if count == (len_convs - 2) and skip:      skip_connection = x    count += 1    if conv['stride'] > 1: x = ZeroPadding2D(((1,0),(1,0)))(x) # peculiar padding as darknet prefer left and top    x = Conv2D(conv['filter'],           conv['kernel'],           strides=conv['stride'],           padding='valid' if conv['stride'] > 1 else 'same', # peculiar padding as darknet prefer left and top           name='conv_' + str(conv['layer_idx']),           use_bias=False if conv['bnorm'] else True)(x)    if conv['bnorm']: x = BatchNormalization(epsilon=0.001, name='bnorm_' + str(conv['layer_idx']))(x)    if conv['leaky']: x = LeakyReLU(alpha=0.1, name='leaky_' + str(conv['layer_idx']))(x)  return add([skip_connection, x]) if skip else x#SPP block uses three pooling layers of sizes [5, 9, 13] with strides one and all outputs together with the input are concatenated to be fed  #to the FC block 
开发者ID:produvia,项目名称:ai-platform,代码行数:24,代码来源:yolov3_weights_to_keras.py


示例3: _conv_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def _conv_block(inp, convs, do_skip=True):    x = inp    count = 0        for conv in convs:        if count == (len(convs) - 2) and do_skip:            skip_connection = x        count += 1                if conv['stride'] > 1: x = ZeroPadding2D(((1,0),(1,0)))(x) # unlike tensorflow darknet prefer left and top paddings        x = Conv2D(conv['filter'],                    conv['kernel'],                    strides=conv['stride'],                    padding='valid' if conv['stride'] > 1 else 'same', # unlike tensorflow darknet prefer left and top paddings                   name='conv_' + str(conv['layer_idx']),                    use_bias=False if conv['bnorm'] else True)(x)        if conv['bnorm']: x = BatchNormalization(epsilon=0.001, name='bnorm_' + str(conv['layer_idx']))(x)        if conv['leaky']: x = LeakyReLU(alpha=0.1, name='leaky_' + str(conv['layer_idx']))(x)    return add([skip_connection, x]) if do_skip else x 
开发者ID:OlafenwaMoses,项目名称:ImageAI,代码行数:22,代码来源:yolo.py


示例4: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def build_discriminator(self):        """Discriminator network with PatchGAN."""        inp_img = Input(shape = (self.image_size, self.image_size, 3))        x = ZeroPadding2D(padding = 1)(inp_img)        x = Conv2D(filters = self.d_conv_dim, kernel_size = 4, strides = 2, padding = 'valid', use_bias = False)(x)        x = LeakyReLU(0.01)(x)            curr_dim = self.d_conv_dim        for i in range(1, self.d_repeat_num):            x = ZeroPadding2D(padding = 1)(x)            x = Conv2D(filters = curr_dim*2, kernel_size = 4, strides = 2, padding = 'valid')(x)            x = LeakyReLU(0.01)(x)            curr_dim = curr_dim * 2            kernel_size = int(self.image_size / np.power(2, self.d_repeat_num))            out_src = ZeroPadding2D(padding = 1)(x)        out_src = Conv2D(filters = 1, kernel_size = 3, strides = 1, padding = 'valid', use_bias = False)(out_src)            out_cls = Conv2D(filters = self.c_dim, kernel_size = kernel_size, strides = 1, padding = 'valid', use_bias = False)(x)        out_cls = Reshape((self.c_dim, ))(out_cls)            return Model(inp_img, [out_src, out_cls]) 
开发者ID:hoangthang1607,项目名称:StarGAN-Keras,代码行数:25,代码来源:StarGAN.py


示例5: residual

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def residual(_x, out_dim, name, stride=1):  shortcut = _x  num_channels = K.int_shape(shortcut)[-1]  _x = ZeroPadding2D(padding=1, name=name + '.pad1')(_x)  _x = Conv2D(out_dim, 3, strides=stride, use_bias=False, name=name + '.conv1')(_x)  _x = BatchNormalization(epsilon=1e-5, name=name + '.bn1')(_x)  _x = Activation('relu', name=name + '.relu1')(_x)  _x = Conv2D(out_dim, 3, padding='same', use_bias=False, name=name + '.conv2')(_x)  _x = BatchNormalization(epsilon=1e-5, name=name + '.bn2')(_x)  if num_channels != out_dim or stride != 1:    shortcut = Conv2D(out_dim, 1, strides=stride, use_bias=False, name=name + '.shortcut.0')(        shortcut)    shortcut = BatchNormalization(epsilon=1e-5, name=name + '.shortcut.1')(shortcut)  _x = Add(name=name + '.add')([_x, shortcut])  _x = Activation('relu', name=name + '.relu')(_x)  return _x 
开发者ID:see--,项目名称:keras-centernet,代码行数:21,代码来源:hourglass.py


示例6: conv2d_bn

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def conv2d_bn(x,              layer=None,              cv1_out=None,              cv1_filter=(1, 1),              cv1_strides=(1, 1),              cv2_out=None,              cv2_filter=(3, 3),              cv2_strides=(1, 1),              padding=None):    num = '' if cv2_out == None else '1'    tensor = Conv2D(cv1_out, cv1_filter, strides=cv1_strides, data_format='channels_first', name=layer+'_conv'+num)(x)    tensor = BatchNormalization(axis=1, epsilon=0.00001, name=layer+'_bn'+num)(tensor)    tensor = Activation('relu')(tensor)    if padding == None:        return tensor    tensor = ZeroPadding2D(padding=padding, data_format='channels_first')(tensor)    if cv2_out == None:        return tensor    tensor = Conv2D(cv2_out, cv2_filter, strides=cv2_strides, data_format='channels_first', name=layer+'_conv'+'2')(tensor)    tensor = BatchNormalization(axis=1, epsilon=0.00001, name=layer+'_bn'+'2')(tensor)    tensor = Activation('relu')(tensor)    return tensor 
开发者ID:akshaybahadur21,项目名称:Facial-Recognition-using-Facenet,代码行数:24,代码来源:fr_utils.py


示例7: inception_block_1c

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def inception_block_1c(X):    X_3x3 = fr_utils.conv2d_bn(X,                           layer='inception_3c_3x3',                           cv1_out=128,                           cv1_filter=(1, 1),                           cv2_out=256,                           cv2_filter=(3, 3),                           cv2_strides=(2, 2),                           padding=(1, 1))    X_5x5 = fr_utils.conv2d_bn(X,                           layer='inception_3c_5x5',                           cv1_out=32,                           cv1_filter=(1, 1),                           cv2_out=64,                           cv2_filter=(5, 5),                           cv2_strides=(2, 2),                           padding=(2, 2))    X_pool = MaxPooling2D(pool_size=3, strides=2, data_format='channels_first')(X)    X_pool = ZeroPadding2D(padding=((0, 1), (0, 1)), data_format='channels_first')(X_pool)    inception = concatenate([X_3x3, X_5x5, X_pool], axis=1)    return inception 
开发者ID:akshaybahadur21,项目名称:Facial-Recognition-using-Facenet,代码行数:27,代码来源:inception_blocks_v2.py


示例8: inception_block_2b

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def inception_block_2b(X):    #inception4e    X_3x3 = fr_utils.conv2d_bn(X,                           layer='inception_4e_3x3',                           cv1_out=160,                           cv1_filter=(1, 1),                           cv2_out=256,                           cv2_filter=(3, 3),                           cv2_strides=(2, 2),                           padding=(1, 1))    X_5x5 = fr_utils.conv2d_bn(X,                           layer='inception_4e_5x5',                           cv1_out=64,                           cv1_filter=(1, 1),                           cv2_out=128,                           cv2_filter=(5, 5),                           cv2_strides=(2, 2),                           padding=(2, 2))        X_pool = MaxPooling2D(pool_size=3, strides=2, data_format='channels_first')(X)    X_pool = ZeroPadding2D(padding=((0, 1), (0, 1)), data_format='channels_first')(X_pool)    inception = concatenate([X_3x3, X_5x5, X_pool], axis=1)    return inception 
开发者ID:akshaybahadur21,项目名称:Facial-Recognition-using-Facenet,代码行数:27,代码来源:inception_blocks_v2.py


示例9: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def build_discriminator(self):        model = Sequential()        model.add(Conv2D(32, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Conv2D(64, kernel_size=3, strides=2, padding="same"))        model.add(ZeroPadding2D(padding=((0,1),(0,1))))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(128, kernel_size=3, strides=2, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(256, kernel_size=3, strides=1, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Flatten())        model.summary()        img = Input(shape=self.img_shape)        features = model(img)        valid = Dense(1, activation="sigmoid")(features)        label = Dense(self.num_classes+1, activation="softmax")(features)        return Model(img, [valid, label]) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:32,代码来源:sgan.py


示例10: build_disk_and_q_net

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def build_disk_and_q_net(self):        img = Input(shape=self.img_shape)        # Shared layers between discriminator and recognition network        model = Sequential()        model.add(Conv2D(64, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Conv2D(128, kernel_size=3, strides=2, padding="same"))        model.add(ZeroPadding2D(padding=((0,1),(0,1))))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(256, kernel_size=3, strides=2, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(512, kernel_size=3, strides=2, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Flatten())        img_embedding = model(img)        # Discriminator        validity = Dense(1, activation='sigmoid')(img_embedding)        # Recognition        q_net = Dense(128, activation='relu')(img_embedding)        label = Dense(self.num_classes, activation='softmax')(q_net)        # Return discriminator and recognition network        return Model(img, validity), Model(img, label) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:37,代码来源:infogan.py


示例11: build_critic

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def build_critic(self):        model = Sequential()        model.add(Conv2D(16, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Conv2D(32, kernel_size=3, strides=2, padding="same"))        model.add(ZeroPadding2D(padding=((0,1),(0,1))))        model.add(BatchNormalization(momentum=0.8))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Conv2D(64, kernel_size=3, strides=2, padding="same"))        model.add(BatchNormalization(momentum=0.8))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Conv2D(128, kernel_size=3, strides=1, padding="same"))        model.add(BatchNormalization(momentum=0.8))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Flatten())        model.add(Dense(1))        model.summary()        img = Input(shape=self.img_shape)        validity = model(img)        return Model(img, validity) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:31,代码来源:wgan.py


示例12: build_discriminator

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def build_discriminator(self):        model = Sequential()        model.add(Conv2D(16, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Conv2D(32, kernel_size=3, strides=2, padding="same"))        model.add(ZeroPadding2D(padding=((0,1),(0,1))))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(64, kernel_size=3, strides=2, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(BatchNormalization(momentum=0.8))        model.add(Conv2D(128, kernel_size=3, strides=1, padding="same"))        model.add(LeakyReLU(alpha=0.2))        model.add(Dropout(0.25))        model.add(Flatten())        model.summary()        img = Input(shape=self.img_shape)        # Extract feature representation        features = model(img)        # Determine validity and label of the image        validity = Dense(1, activation="sigmoid")(features)        label = Dense(self.num_classes, activation="softmax")(features)        return Model(img, [validity, label]) 
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:35,代码来源:acgan.py


示例13: resnet_graph

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def resnet_graph(input_image, architecture, stage5=False, train_bn=True):    """Build a ResNet graph.        architecture: Can be resnet50 or resnet101        stage5: Boolean. If False, stage5 of the network is not created        train_bn: Boolean. Train or freeze Batch Norm layers    """    assert architecture in ["resnet50", "resnet101"]    # Stage 1    x = KL.ZeroPadding2D((3, 3))(input_image)    x = KL.Conv2D(64, (7, 7), strides=(2, 2), name='conv1', use_bias=True)(x)    x = BatchNorm(name='bn_conv1')(x, training=train_bn)    x = KL.Activation('relu')(x)    C1 = x = KL.MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)    # Stage 2    x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1), train_bn=train_bn)    x = identity_block(x, 3, [64, 64, 256], stage=2, block='b', train_bn=train_bn)    C2 = x = identity_block(x, 3, [64, 64, 256], stage=2, block='c', train_bn=train_bn)    # Stage 3    x = conv_block(x, 3, [128, 128, 512], stage=3, block='a', train_bn=train_bn)    x = identity_block(x, 3, [128, 128, 512], stage=3, block='b', train_bn=train_bn)    x = identity_block(x, 3, [128, 128, 512], stage=3, block='c', train_bn=train_bn)    C3 = x = identity_block(x, 3, [128, 128, 512], stage=3, block='d', train_bn=train_bn)    # Stage 4    x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a', train_bn=train_bn)    block_count = {"resnet50": 5, "resnet101": 22}[architecture]    for i in range(block_count):        x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i), train_bn=train_bn)    C4 = x    # Stage 5    if stage5:        x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a', train_bn=train_bn)        x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b', train_bn=train_bn)        C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c', train_bn=train_bn)    else:        C5 = None    return [C1, C2, C3, C4, C5]#############################################################  Proposal Layer############################################################ 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:43,代码来源:model.py


示例14: resblock_body

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def resblock_body(x, num_filters, num_blocks):    '''A series of resblocks starting with a downsampling Convolution2D'''    # Darknet uses left and top padding instead of 'same' mode    x = ZeroPadding2D(((1,0),(1,0)))(x)    x = DarknetConv2D_BN_Leaky(num_filters, (3,3), strides=(2,2))(x)    for i in range(num_blocks):        y = compose(                DarknetConv2D_BN_Leaky(num_filters//2, (1,1)),                DarknetConv2D_BN_Leaky(num_filters, (3,3)))(x)        x = Add()([x,y])    return x 
开发者ID:bing0037,项目名称:keras-yolo3,代码行数:13,代码来源:model.py


示例15: SepConv_BN

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def SepConv_BN(x, filters, prefix, stride=1, kernel_size=3, rate=1, depth_activation=False, epsilon=1e-3):    # 计算padding的数量,hw是否需要收缩    if stride == 1:        depth_padding = 'same'    else:        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)        pad_total = kernel_size_effective - 1        pad_beg = pad_total // 2        pad_end = pad_total - pad_beg        x = ZeroPadding2D((pad_beg, pad_end))(x)        depth_padding = 'valid'        # 如果需要激活函数    if not depth_activation:        x = Activation('relu')(x)    # 分离卷积,首先3x3分离卷积,再1x1卷积    # 3x3采用膨胀卷积    x = DepthwiseConv2D((kernel_size, kernel_size), strides=(stride, stride), dilation_rate=(rate, rate),                        padding=depth_padding, use_bias=False, name=prefix + '_depthwise')(x)    x = BatchNormalization(name=prefix + '_depthwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    # 1x1卷积,进行压缩    x = Conv2D(filters, (1, 1), padding='same',               use_bias=False, name=prefix + '_pointwise')(x)    x = BatchNormalization(name=prefix + '_pointwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    return x 
开发者ID:bubbliiiing,项目名称:Semantic-Segmentation,代码行数:34,代码来源:deeplab.py


示例16: identity_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def identity_block(input_tensor, kernel_size, filters, stage, block):    """    The identity_block is the block that has no conv layer at shortcut    # Arguments        input_tensor: input tensor        kernel_size: defualt 3, the kernel size of middle conv layer at main path        filters: list of integers, the nb_filters of 3 conv layer at main path        stage: integer, current stage label, used for generating layer names        block: 'a','b'..., current block label, used for generating layer names    """    eps = 1.1e-5    nb_filter1, nb_filter2, nb_filter3 = filters    conv_name_base = 'res' + str(stage) + block + '_branch'    bn_name_base = 'bn' + str(stage) + block + '_branch'    scale_name_base = 'scale' + str(stage) + block + '_branch'    if K.image_data_format() == 'channels_last':        bn_axis = 3    else:        bn_axis = 1    x = Conv2D(nb_filter1, (1, 1), name=conv_name_base + '2a', use_bias=False)(input_tensor)    x = BatchNormalization(epsilon=eps, axis=bn_axis, name=bn_name_base + '2a')(x)    x = Scale(axis=bn_axis, name=scale_name_base + '2a')(x)    x = Activation('relu', name=conv_name_base + '2a_relu')(x)    x = ZeroPadding2D((1, 1), name=conv_name_base + '2b_zeropadding')(x)    x = Conv2D(nb_filter2, (kernel_size, kernel_size), name=conv_name_base + '2b', use_bias=False)(x)    x = BatchNormalization(epsilon=eps, axis=bn_axis, name=bn_name_base + '2b')(x)    x = Scale(axis=bn_axis, name=scale_name_base + '2b')(x)    x = Activation('relu', name=conv_name_base + '2b_relu')(x)    x = Conv2D(nb_filter3, (1, 1), name=conv_name_base + '2c', use_bias=False)(x)    x = BatchNormalization(epsilon=eps, axis=bn_axis, name=bn_name_base + '2c')(x)    x = Scale(axis=bn_axis, name=scale_name_base + '2c')(x)    x = add([x, input_tensor], name='res' + str(stage) + block)    x = Activation('relu', name='res' + str(stage) + block + '_relu')(x)    return x 
开发者ID:CMU-CREATE-Lab,项目名称:deep-smoke-machine,代码行数:41,代码来源:resnet_152_keras.py


示例17: identity_block

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def identity_block(input_tensor, kernel_size, filters, stage, block):    '''The identity_block is the block that has no conv layer at shortcut    # Arguments        input_tensor: input tensor        kernel_size: defualt 3, the kernel size of middle conv layer at main path        filters: list of integers, the nb_filters of 3 conv layer at main path        stage: integer, current stage label, used for generating layer names        block: 'a','b'..., current block label, used for generating layer names    '''    eps = 1.1e-5    nb_filter1, nb_filter2, nb_filter3 = filters    conv_name_base = 'res' + str(stage) + block + '_branch'    bn_name_base = 'bn' + str(stage) + block + '_branch'    scale_name_base = 'scale' + str(stage) + block + '_branch'    x = Conv2D(nb_filter1, (1, 1), name=conv_name_base + '2a', use_bias=False)(input_tensor)    x = BatchNormalization(epsilon=eps, axis=bn_axis, name=bn_name_base + '2a')(x)    x = Scale(axis=bn_axis, name=scale_name_base + '2a')(x)    x = Activation('relu', name=conv_name_base + '2a_relu')(x)    x = ZeroPadding2D((1, 1), name=conv_name_base + '2b_zeropadding')(x)    x = Conv2D(nb_filter2, (kernel_size, kernel_size),                      name=conv_name_base + '2b', use_bias=False)(x)    x = BatchNormalization(epsilon=eps, axis=bn_axis, name=bn_name_base + '2b')(x)    x = Scale(axis=bn_axis, name=scale_name_base + '2b')(x)    x = Activation('relu', name=conv_name_base + '2b_relu')(x)    x = Conv2D(nb_filter3, (1, 1), name=conv_name_base + '2c', use_bias=False)(x)    x = BatchNormalization(epsilon=eps, axis=bn_axis, name=bn_name_base + '2c')(x)    x = Scale(axis=bn_axis, name=scale_name_base + '2c')(x)    x = add([x, input_tensor], name='res' + str(stage) + block)    x = Activation('relu', name='res' + str(stage) + block + '_relu')(x)    return x 
开发者ID:foamliu,项目名称:Car-Recognition,代码行数:36,代码来源:resnet_152.py


示例18: resnet_graph

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def resnet_graph(input_image, architecture, stage5=False):    assert architecture in ["resnet50", "resnet101"]    # Stage 1    x = KL.ZeroPadding2D((3, 3))(input_image)    x = KL.Conv2D(64, (7, 7), strides=(2, 2), name='conv1', use_bias=True)(x)    x = BatchNorm(axis=3, name='bn_conv1')(x)    x = KL.Activation('relu')(x)    C1 = x = KL.MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)    # Stage 2    x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1))    x = identity_block(x, 3, [64, 64, 256], stage=2, block='b')    C2 = x = identity_block(x, 3, [64, 64, 256], stage=2, block='c')    # Stage 3    x = conv_block(x, 3, [128, 128, 512], stage=3, block='a')    x = identity_block(x, 3, [128, 128, 512], stage=3, block='b')    x = identity_block(x, 3, [128, 128, 512], stage=3, block='c')    C3 = x = identity_block(x, 3, [128, 128, 512], stage=3, block='d')    # Stage 4    x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a')    block_count = {"resnet50": 5, "resnet101": 22}[architecture]    for i in range(block_count):        x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i))    C4 = x    # Stage 5    if stage5:        x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a')        x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b')        C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c')    else:        C5 = None    return [C1, C2, C3, C4, C5]#############################################################  Proposal Layer############################################################ 
开发者ID:SunskyF,项目名称:EasyPR-python,代码行数:38,代码来源:model.py


示例19: SepConv_BN

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def SepConv_BN(x, filters, prefix, stride=1, kernel_size=3, rate=1, depth_activation=False, epsilon=1e-3):    """ SepConv with BN between depthwise & pointwise. Optionally add activation after BN        Implements right "same" padding for even kernel sizes        Args:            x: input tensor            filters: num of filters in pointwise convolution            prefix: prefix before name            stride: stride at depthwise conv            kernel_size: kernel size for depthwise convolution            rate: atrous rate for depthwise convolution            depth_activation: flag to use activation between depthwise & poinwise convs            epsilon: epsilon to use in BN layer    """    if stride == 1:        depth_padding = 'same'    else:        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)        pad_total = kernel_size_effective - 1        pad_beg = pad_total // 2        pad_end = pad_total - pad_beg        x = ZeroPadding2D((pad_beg, pad_end))(x)        depth_padding = 'valid'    if not depth_activation:        x = Activation('relu')(x)    x = DepthwiseConv2D((kernel_size, kernel_size), strides=(stride, stride), dilation_rate=(rate, rate),                        padding=depth_padding, use_bias=False, name=prefix + '_depthwise')(x)    x = BatchNormalization(name=prefix + '_depthwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    x = Conv2D(filters, (1, 1), padding='same',               use_bias=False, name=prefix + '_pointwise')(x)    x = BatchNormalization(name=prefix + '_pointwise_BN', epsilon=epsilon)(x)    if depth_activation:        x = Activation('relu')(x)    return x 
开发者ID:andrewekhalel,项目名称:edafa,代码行数:40,代码来源:model.py


示例20: _conv2d_same

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import ZeroPadding2D [as 别名]def _conv2d_same(x, filters, prefix, stride=1, kernel_size=3, rate=1):    """Implements right 'same' padding for even kernel sizes        Without this there is a 1 pixel drift when stride = 2        Args:            x: input tensor            filters: num of filters in pointwise convolution            prefix: prefix before name            stride: stride at depthwise conv            kernel_size: kernel size for depthwise convolution            rate: atrous rate for depthwise convolution    """    if stride == 1:        return Conv2D(filters,                      (kernel_size, kernel_size),                      strides=(stride, stride),                      padding='same', use_bias=False,                      dilation_rate=(rate, rate),                      name=prefix)(x)    else:        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)        pad_total = kernel_size_effective - 1        pad_beg = pad_total // 2        pad_end = pad_total - pad_beg        x = ZeroPadding2D((pad_beg, pad_end))(x)        return Conv2D(filters,                      (kernel_size, kernel_size),                      strides=(stride, stride),                      padding='valid', use_bias=False,                      dilation_rate=(rate, rate),                      name=prefix)(x) 
开发者ID:andrewekhalel,项目名称:edafa,代码行数:32,代码来源:model.py


51自学网,即我要自学网,自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1