python类AveragePooling2D()的实例源码

ddpg.py 文件源码 项目:Learning-to-navigate-without-a-map 作者: ToniRV 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def create_actor_network(self, state_size, action_dim):
        """Create actor network."""
        print ("[MESSAGE] Build actor network.""")
        S = Input(shape=state_size)
        h_0 = Conv2D(32, (3, 3), padding="same",
                     kernel_regularizer=l2(0.0001),
                     activation="relu")(S)
        h_1 = Conv2D(32, (3, 3), padding="same",
                     kernel_regularizer=l2(0.0001),
                     activation="relu")(h_0)
        h_1 = AveragePooling2D(2, 2)(h_1)
        h_1 = Flatten()(h_1)
        h_1 = Dense(600, activation="relu")(h_1)
        A = Dense(action_dim, activation="softmax")(h_1)

        model = Model(inputs=S, outputs=A)

        return model, model.trainable_weights, S
densenet.py 文件源码 项目:DenseNetKeras 作者: SulemanKazi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def addTransition(previousLayer, nChannels, nOutChannels, dropRate, blockNum):

    bn = BatchNormalization(name = 'tr_BatchNorm_{}'.format(blockNum), axis = 1)(previousLayer)

    relu = Activation('relu', name ='tr_relu_{}'.format(blockNum))(bn)

    conv = Convolution2D(nOutChannels, 1, 1, border_mode='same', name='tr_conv_{}'.format(blockNum))(relu)

    if dropRate is not None:

        dp = Dropout(dropRate, name='tr_dropout_{}'.format)(conv)

        avgPool = AveragePooling2D(pool_size=(2, 2))(dp)

    else:
        avgPool = AveragePooling2D(pool_size=(2, 2))(conv)

    return avgPool
hintbot.py 文件源码 项目:hintbot 作者: madebyollin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def createModel(w=None,h=None):
    # Input placeholder
    original = Input(shape=(w, h, 4), name='icon_goes_here')

    # Model layer stack
    x = original
    x = Convolution2D(64, 4, 4, activation='relu', border_mode='same', b_regularizer=l2(0.1))(x)
    x = Convolution2D(64, 4, 4, activation='relu', border_mode='same', b_regularizer=l2(0.1))(x)
    x = Convolution2D(64, 4, 4, activation='relu', border_mode='same', b_regularizer=l2(0.1))(x)
    x = Convolution2D(64, 4, 4, activation='relu', border_mode='same', b_regularizer=l2(0.1))(x)
    x = AveragePooling2D((2, 2), border_mode='valid')(x)
    x = Convolution2D(16, 4, 4, activation='relu', border_mode='same', b_regularizer=l2(0.1))(x)
    x = Convolution2D(4, 4, 4, activation='relu', border_mode='same',  b_regularizer=l2(0.1))(x)
    downscaled = x

    # Compile model
    hintbot = Model(input=original, output=downscaled)
    hintbot.compile(optimizer='adam', loss='mean_squared_error')
    # Train
    if (os.path.isfile(load_weights_filepath)):
        hintbot.load_weights(load_weights_filepath)
    return hintbot
neuralnets.py 文件源码 项目:Gene-prediction 作者: sriram2093 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def classifier_layers(x, input_shape, stage_num, trainable=False):

    # compile times on theano tend to be very high, so we use smaller ROI pooling regions to workaround
    # (hence a smaller stride in the region that follows the ROI pool)
    if K.backend() == 'tensorflow':
        x = conv_block_td(x, 3, [512, 512, 1024], stage=stage_num, block='a', input_shape=input_shape, strides=(1, 2), trainable=trainable)
    elif K.backend() == 'theano':
        x = conv_block_td(x, 3, [512, 512, 1024], stage=stage_num, block='a', input_shape=input_shape, strides=(1, 1), trainable=trainable)

    print 'INFO: Classifier layers x block a: ', x
    x = identity_block_td(x, 3, [512, 512, 1024], stage=stage_num, block='c', trainable=trainable)
    print 'INFO: Classifier layers x block b: ', x
    x = identity_block_td(x, 3, [512, 512, 1024], stage=stage_num, block='d', trainable=trainable)
    print 'INFO: Classifier layers x block c: ', x

    #x = TimeDistributed(AveragePooling2D((2, 1)), name='avg_pool')(x)

    return x
inception_v4.py 文件源码 项目:cnn_finetune 作者: flyyufelix 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def block_inception_a(input):
    if K.image_dim_ordering() == "th":
        channel_axis = 1
    else:
        channel_axis = -1

    branch_0 = conv2d_bn(input, 96, 1, 1)

    branch_1 = conv2d_bn(input, 64, 1, 1)
    branch_1 = conv2d_bn(branch_1, 96, 3, 3)

    branch_2 = conv2d_bn(input, 64, 1, 1)
    branch_2 = conv2d_bn(branch_2, 96, 3, 3)
    branch_2 = conv2d_bn(branch_2, 96, 3, 3)

    branch_3 = AveragePooling2D((3,3), strides=(1,1), border_mode='same')(input)
    branch_3 = conv2d_bn(branch_3, 96, 1, 1)

    x = merge([branch_0, branch_1, branch_2, branch_3], mode='concat', concat_axis=channel_axis)
    return x
inception_v4.py 文件源码 项目:cnn_finetune 作者: flyyufelix 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def block_inception_b(input):
    if K.image_dim_ordering() == "th":
        channel_axis = 1
    else:
        channel_axis = -1

    branch_0 = conv2d_bn(input, 384, 1, 1)

    branch_1 = conv2d_bn(input, 192, 1, 1)
    branch_1 = conv2d_bn(branch_1, 224, 1, 7)
    branch_1 = conv2d_bn(branch_1, 256, 7, 1)

    branch_2 = conv2d_bn(input, 192, 1, 1)
    branch_2 = conv2d_bn(branch_2, 192, 7, 1)
    branch_2 = conv2d_bn(branch_2, 224, 1, 7)
    branch_2 = conv2d_bn(branch_2, 224, 7, 1)
    branch_2 = conv2d_bn(branch_2, 256, 1, 7)

    branch_3 = AveragePooling2D((3,3), strides=(1,1), border_mode='same')(input)
    branch_3 = conv2d_bn(branch_3, 128, 1, 1)

    x = merge([branch_0, branch_1, branch_2, branch_3], mode='concat', concat_axis=channel_axis)
    return x
dqn.py 文件源码 项目:SerpentAI 作者: SerpentAI 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _initialize_model(self):
        input_layer = Input(shape=self.input_shape)

        tower_1 = Convolution2D(16, 1, 1, border_mode="same", activation="elu")(input_layer)
        tower_1 = Convolution2D(16, 3, 3, border_mode="same", activation="elu")(tower_1)

        tower_2 = Convolution2D(16, 1, 1, border_mode="same", activation="elu")(input_layer)
        tower_2 = Convolution2D(16, 3, 3, border_mode="same", activation="elu")(tower_2)
        tower_2 = Convolution2D(16, 3, 3, border_mode="same", activation="elu")(tower_2)

        tower_3 = MaxPooling2D((3, 3), strides=(1, 1), border_mode="same")(input_layer)
        tower_3 = Convolution2D(16, 1, 1, border_mode="same", activation="elu")(tower_3)

        merged_layer = merge([tower_1, tower_2, tower_3], mode="concat", concat_axis=1)

        output = AveragePooling2D((7, 7), strides=(8, 8))(merged_layer)
        output = Flatten()(output)
        output = Dense(self.action_count)(output)

        model = Model(input=input_layer, output=output)
        model.compile(rmsprop(lr=self.model_learning_rate, clipvalue=1), "mse")

        return model
trainer.py 文件源码 项目:deepanalytics_compe26_benchmark 作者: takagiwa-ss 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def resnet(repetition=2, k=1):
    '''Wide Residual Network (with a slight modification)
    depth == repetition*6 + 2
    '''
    from keras.models import Model
    from keras.layers import Input, Dense, Flatten, AveragePooling2D
    from keras.regularizers import l2

    input_shape = (1, _img_len, _img_len)
    output_dim = len(_columns)

    x = Input(shape=input_shape)

    z = conv2d(nb_filter=8, k_size=5, downsample=True)(x)        # out_shape ==    8, _img_len/ 2, _img_len/ 2
    z = bn_lrelu(0.01)(z)
    z = residual_block(nb_filter=k*16, repetition=repetition)(z) # out_shape == k*16, _img_len/ 4, _img_len/ 4
    z = residual_block(nb_filter=k*32, repetition=repetition)(z) # out_shape == k*32, _img_len/ 8, _img_len/ 8
    z = residual_block(nb_filter=k*64, repetition=repetition)(z) # out_shape == k*64, _img_len/16, _img_len/16
    z = AveragePooling2D((_img_len/16, _img_len/16))(z)
    z = Flatten()(z)
    z = Dense(output_dim=output_dim, activation='sigmoid', W_regularizer=l2(_Wreg_l2), init='zero')(z)

    return Model(input=x, output=z)
model.py 文件源码 项目:deepascii 作者: awentzonline 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_model(
        img_shape, charset_features, layer_name='block2_conv1',
        output_pool=2, pool_type='max'):
    if K.image_dim_ordering():
        num_chars, char_h, char_w, char_channels = charset_features.shape
        axis = -1
    else:
        num_chars, char_channels, char_h, char_w = charset_features.shape
        axis = 1
    vgg = vgg16.VGG16(input_shape=img_shape, include_top=False)
    layer = vgg.get_layer(layer_name)
    x = layer.output
    # TODO: theano dim order
    features_W = charset_features.transpose((1, 2, 3, 0)).astype(np.float32)
    features_W = features_W[::-1, ::-1, :, :] / np.sqrt(np.sum(np.square(features_W), axis=(0, 1), keepdims=True))
    x = BatchNormalization(mode=2)(x)
    x = Convolution2D(
        num_chars, char_h, char_w, border_mode='valid',
        weights=[features_W, np.zeros(num_chars)])(x)
    if output_pool > 1:
        pool_class = dict(max=MaxPooling2D, avg=AveragePooling2D)[pool_type]
        x = pool_class((output_pool, output_pool))(x)
    #x = Argmax(axis)(x)
    model = Model([vgg.input], [x])
    return model
layers_builder.py 文件源码 项目:PSPNet-Keras-tensorflow 作者: Vladkryvoruchko 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def interp_block(prev_layer, level, feature_map_shape, input_shape):
    if input_shape == (473, 473):
        kernel_strides_map = {1: 60,
                              2: 30,
                              3: 20,
                              6: 10}
    elif input_shape == (713, 713):
        kernel_strides_map = {1: 90,
                              2: 45,
                              3: 30,
                              6: 15}
    else:
        print("Pooling parameters for input shape ", input_shape, " are not defined.")
        exit(1)

    names = [
        "conv5_3_pool" + str(level) + "_conv",
        "conv5_3_pool" + str(level) + "_conv_bn"
        ]
    kernel = (kernel_strides_map[level], kernel_strides_map[level])
    strides = (kernel_strides_map[level], kernel_strides_map[level])
    prev_layer = AveragePooling2D(kernel, strides=strides)(prev_layer)
    prev_layer = Conv2D(512, (1, 1), strides=(1, 1), name=names[0],
                        use_bias=False)(prev_layer)
    prev_layer = BN(name=names[1])(prev_layer)
    prev_layer = Activation('relu')(prev_layer)
    prev_layer = Lambda(Interp, arguments={'shape': feature_map_shape})(prev_layer)
    return prev_layer
ddpg.py 文件源码 项目:Learning-to-navigate-without-a-map 作者: ToniRV 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def create_critic_network(self, state_size, action_dim):
        """create critic network."""
        print ("[MESSAGE] Build critic network.""")
        S = Input(shape=state_size)
        A = Input(shape=(action_dim,))

        # input
        h_0 = Conv2D(32, (3, 3), padding="same",
                     kernel_regularizer=l2(0.0001),
                     activation="relu")(S)
        h_1 = Conv2D(32, (3, 3), padding="same",
                     kernel_regularizer=l2(0.0001),
                     activation="relu")(h_0)
        h_1 = AveragePooling2D(2, 2)(h_1)
        h_1 = Flatten()(h_1)
        h_1 = Dense(600, activation="relu")(h_1)

        # action
        a_1 = Dense(600, activation="linear")(A)
        h_2 = add([h_1, a_1])
        h_3 = Dense(600, activation="relu")(h_2)
        V = Dense(action_dim, activation="softmax")(h_3)

        model = Model(inputs=[S, A], outputs=V)
        model.compile(loss='categorical_crossentropy',
                      optimizer="adam")
        return model, A, S
nasnet.py 文件源码 项目:keras-contrib 作者: farizrahman4u 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _add_auxiliary_head(x, classes, weight_decay):
    '''Adds an auxiliary head for training the model

    From section A.7 "Training of ImageNet models" of the paper, all NASNet models are
    trained using an auxiliary classifier around 2/3 of the depth of the network, with
    a loss weight of 0.4

    # Arguments
        x: input tensor
        classes: number of output classes
        weight_decay: l2 regularization weight

    # Returns
        a keras Tensor
    '''
    img_height = 1 if K.image_data_format() == 'channels_last' else 2
    img_width = 2 if K.image_data_format() == 'channels_last' else 3
    channel_axis = 1 if K.image_data_format() == 'channels_first' else -1

    with K.name_scope('auxiliary_branch'):
        auxiliary_x = Activation('relu')(x)
        auxiliary_x = AveragePooling2D((5, 5), strides=(3, 3), padding='valid', name='aux_pool')(auxiliary_x)
        auxiliary_x = Conv2D(128, (1, 1), padding='same', use_bias=False, name='aux_conv_projection',
                             kernel_initializer='he_normal', kernel_regularizer=l2(weight_decay))(auxiliary_x)
        auxiliary_x = BatchNormalization(axis=channel_axis, momentum=_BN_DECAY, epsilon=_BN_EPSILON,
                                         name='aux_bn_projection')(auxiliary_x)
        auxiliary_x = Activation('relu')(auxiliary_x)

        auxiliary_x = Conv2D(768, (auxiliary_x._keras_shape[img_height], auxiliary_x._keras_shape[img_width]),
                             padding='valid', use_bias=False, kernel_initializer='he_normal',
                             kernel_regularizer=l2(weight_decay), name='aux_conv_reduction')(auxiliary_x)
        auxiliary_x = BatchNormalization(axis=channel_axis, momentum=_BN_DECAY, epsilon=_BN_EPSILON,
                                         name='aux_bn_reduction')(auxiliary_x)
        auxiliary_x = Activation('relu')(auxiliary_x)

        auxiliary_x = GlobalAveragePooling2D()(auxiliary_x)
        auxiliary_x = Dense(classes, activation='softmax', kernel_regularizer=l2(weight_decay),
                            name='aux_predictions')(auxiliary_x)
    return auxiliary_x
models.py 文件源码 项目:keras-squeezenet 作者: dvbuntu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_squeezenet(nb_classes):

    input_img = Input(shape=(3, 227, 227))
    x = Convolution2D(96, 7, 7, subsample=(2, 2), border_mode='valid')(input_img)
    x = Activation('relu')(x)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2))(x)

    x = fire_module(x, 16, 64)
    x = fire_module(x, 16, 64)
    x = fire_module(x, 32, 128)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2))(x)

    x = fire_module(x, 32, 192)
    x = fire_module(x, 48, 192)
    x = fire_module(x, 48, 192)
    x = fire_module(x, 64, 256)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2))(x)

    x = fire_module(x, 64, 256)
    x = Dropout(0.5)(x)

    x = ZeroPadding2D(padding=(1, 1))(x)
    x = Convolution2D(nb_classes, 1, 1, border_mode='valid')(x)

    # global pooling not available
    x = AveragePooling2D(pool_size=(15, 15))(x)
    x = Flatten()(x)
    out = Dense(nb_classes, activation='softmax')(x)
    model = Model(input=input_img, output=[out])
    return model
models.py 文件源码 项目:keras-squeezenet 作者: dvbuntu 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_small_squeezenet(nb_classes):

    input_img = Input(shape=(3, 32, 32))
    x = Convolution2D(16, 3, 3, border_mode='same')(input_img)
    x = Activation('relu')(x)
    x = MaxPooling2D(pool_size=(3, 3))(x)

    x = fire_module(x, 32, 128)
    x = fire_module(x, 32, 128)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    x = fire_module(x, 48, 192)
    x = fire_module(x, 48, 192)
    x = MaxPooling2D(pool_size=(2, 2))(x)

    x = fire_module(x, 64, 256)
    x = Dropout(0.5)(x)

    x = ZeroPadding2D(padding=(1, 1))(x)
    x = Convolution2D(nb_classes, 1, 1, border_mode='valid')(x)

    # global pooling not available
    x = AveragePooling2D(pool_size=(4, 4))(x)
    x = Flatten()(x)
    out = Dense(nb_classes, activation='softmax')(x)
    model = Model(input=input_img, output=[out])
    return model
m05a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def define_model(image_shape):
    img_input = Input(shape=image_shape)

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=4, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy', 'precision', 'recall', 'fmeasure'])
    model.summary()
    return model
m09a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def define_model(image_shape):
    img_input = Input(shape=image_shape)

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=4, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy', 'precision', 'recall', 'fmeasure'])
    model.summary()
    return model
m02a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def define_model(image_shape, transfer_weights_filepath):
    img_input = Input(shape=image_shape)

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x_orig = Dense(1, activation='sigmoid')(x)

    model_base = Model(img_input, x_orig)
    model_base.load_weights(transfer_weights_filepath)

    bbox = Dense(4, activation='linear', name='bbox')(x)
    model_bbox = Model(img_input, bbox)
    model_bbox.compile(optimizer='adam', loss='mae')
    model_bbox.summary()
    return model_bbox
m04a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def define_model(image_shape, transfer_weights_filepath):
    img_input = Input(shape=image_shape)

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x_orig = Dense(1, activation='sigmoid')(x)

    model_base = Model(img_input, x_orig)
    model_base.load_weights(transfer_weights_filepath)

    bbox = Dense(4, activation='linear', name='bbox')(x)
    model_bbox = Model(img_input, bbox)
    model_bbox.compile(optimizer='adam', loss='mae')
    model_bbox.summary()
    return model_bbox
resnet2d09d.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def define_model(image_shape):
    img_input = Input(shape=image_shape)

    x = Convolution2D(128, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=0, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=0, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=1024, block=0, subsample_factor=2)
    x = res_block(x, nb_filters=1024, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=1024, block=0, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy', 'precision', 'recall'])
    model.summary()
    return model
resnet2d09f.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def define_model(image_shape):
    img_input = Input(shape=image_shape)

    x = Convolution2D(128, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=2, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(8, 8))(x)
    x = Flatten()(x)
    x = Dropout(0.2)(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy', 'precision', 'recall', 'fmeasure'])
    model.summary()
    return model
m02a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def define_model():
    img_input = Input(shape=(32, 32, 1))

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)

    bbox = Dense(4, activation='linear', name='bbox')(x)
    model_bbox = Model(img_input, bbox)
    model_bbox.compile(optimizer='adam', loss='mae')

    return model_bbox
m04a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def define_model():
    img_input = Input(shape=(32, 32, 2))

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)

    bbox = Dense(4, activation='linear', name='bbox')(x)
    model_bbox = Model(img_input, bbox)
    model_bbox.compile(optimizer='adam', loss='mae')

    return model_bbox
m05a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def define_model():
    img_input = Input(shape=(64, 64, 3))

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=4, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy')

    return model
m09a.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def define_model():
    img_input = Input(shape=(64, 64, 5))

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=3, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=3, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=4, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=4, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(3, 3), strides=(2, 2), border_mode='valid')(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy')

    return model
resnet2d09e.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def define_model():
    img_input = Input(shape=(32, 32, 1))

    x = Convolution2D(32, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=32, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=64, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=64, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=128, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=2, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(8, 8))(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy')

    return model
resnet2d09f.py 文件源码 项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def define_model():
    img_input = Input(shape=(32, 32, 1))

    x = Convolution2D(128, 3, 3, subsample=(1, 1), border_mode='same')(img_input)

    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)
    x = res_block(x, nb_filters=128, block=0, subsample_factor=1)

    x = res_block(x, nb_filters=256, block=1, subsample_factor=2)
    x = res_block(x, nb_filters=256, block=1, subsample_factor=1)
    x = res_block(x, nb_filters=256, block=1, subsample_factor=1)

    x = res_block(x, nb_filters=512, block=2, subsample_factor=2)
    x = res_block(x, nb_filters=512, block=2, subsample_factor=1)
    x = res_block(x, nb_filters=512, block=2, subsample_factor=1)

    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)

    x = AveragePooling2D(pool_size=(8, 8))(x)
    x = Flatten()(x)
    x = Dense(1, activation='sigmoid', name='predictions')(x)

    model = Model(img_input, x)
    model.compile(optimizer='adam', loss='binary_crossentropy')

    return model
test_surgeon.py 文件源码 项目:keras-surgeon 作者: BenWhetton 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_delete_channels_averagepooling2d(channel_index, data_format):
    layer = AveragePooling2D([2, 3], data_format=data_format)
    layer_test_helper_flatten_2d(layer, channel_index, data_format)
test_keras2_numeric.py 文件源码 项目:coremltools 作者: apple 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_average_pooling_no_overlap(self):
        # no_overlap: pool_size = strides
        model = Sequential()
        model.add(AveragePooling2D(input_shape=(16,16,3), pool_size=(2, 2),
                               strides=None, padding='valid'))
        self._test_keras_model(model, delta=1e-2)
test_keras2_numeric.py 文件源码 项目:coremltools 作者: apple 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_average_pooling_inception_config_1(self):
        # no_overlap: pool_size = strides
        model = Sequential()
        model.add(AveragePooling2D(input_shape=(16,16,3), pool_size=(3,3),
                               strides=(1,1), padding='same'))
        self._test_keras_model(model, delta=1e-2)
test_keras2_numeric.py 文件源码 项目:coremltools 作者: apple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_tiny_mcrnn_td(self):

        model = Sequential()
        model.add(Conv2D(3,(1,1), input_shape=(2,4,4), padding='same'))
        model.add(AveragePooling2D(pool_size=(2,2)))
        model.add(Reshape((2,3)))
        model.add(TimeDistributed(Dense(5)))

        self._test_keras_model(model)


问题


面经


文章

微信
公众号

扫码关注公众号