当前位置: 首页>>代码示例>>Python>>正文


Python layers.AveragePooling3D方法代码示例

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


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

示例1: transition_layer_3D

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def transition_layer_3D(input_tensor, numFilters, compressionFactor=1.0):

    numOutPutFilters = int(numFilters*compressionFactor)

    if K.image_data_format() == 'channels_last':
        bn_axis = -1
    else:
        bn_axis = 1

    x = BatchNormalization(axis=bn_axis)(input_tensor)
    x = Activation('relu')(x)

    x = Conv3D(numOutPutFilters, (1, 1, 1), strides=(1, 1, 1), padding='same', kernel_initializer='he_normal')(x)

    # downsampling
    x = AveragePooling3D((2, 2, 2), strides=(2, 2, 2), padding='valid', data_format='channels_last', name='')(x)

    return x, numOutPutFilters 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:20,代码来源:densely_connected_cnn_blocks.py

示例2: transition_SE_layer_3D

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def transition_SE_layer_3D(input_tensor, numFilters, compressionFactor=1.0, se_ratio=16):

    numOutPutFilters = int(numFilters*compressionFactor)

    if K.image_data_format() == 'channels_last':
        bn_axis = -1
    else:
        bn_axis = 1

    x = BatchNormalization(axis=bn_axis)(input_tensor)
    x = Activation('relu')(x)

    x = Conv3D(numOutPutFilters, (1, 1, 1), strides=(1, 1, 1), padding='same', kernel_initializer='he_normal')(x)

    # SE Block
    x = squeeze_excitation_block_3D(x, ratio=se_ratio)
    #x = BatchNormalization(axis=bn_axis)(x)

    # downsampling
    x = AveragePooling3D((2, 2, 2), strides=(2, 2, 2), padding='valid', data_format='channels_last', name='')(x)

    #x = squeeze_excitation_block(x, ratio=se_ratio)

    return x, numOutPutFilters 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:26,代码来源:densely_connected_cnn_blocks.py

示例3: inception3D

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def inception3D(image_size, num_labels):
    num_channels=1
    inputs = Input(shape = (image_size, image_size, image_size, num_channels))

    m = Convolution3D(32, 5, 5, 5, subsample=(1, 1, 1), activation='relu', border_mode='valid', input_shape=())(inputs)
    m = MaxPooling3D(pool_size=(2, 2, 2), strides=None, border_mode='same')(m)

    # inception module 0
    branch1x1 = Convolution3D(32, 1, 1, 1, subsample=(1, 1, 1), activation='relu', border_mode='same')(m)
    branch3x3_reduce = Convolution3D(32, 1, 1, 1, subsample=(1, 1, 1), activation='relu', border_mode='same')(m)
    branch3x3 = Convolution3D(64, 3, 3, 3, subsample=(1, 1, 1), activation='relu', border_mode='same')(branch3x3_reduce)
    branch5x5_reduce = Convolution3D(16, 1, 1, 1, subsample=(1, 1, 1), activation='relu', border_mode='same')(m)
    branch5x5 = Convolution3D(32, 5, 5, 5, subsample=(1, 1, 1), activation='relu', border_mode='same')(branch5x5_reduce)
    branch_pool = MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), border_mode='same')(m)
    branch_pool_proj = Convolution3D(32, 1, 1, 1, subsample=(1, 1, 1), activation='relu', border_mode='same')(branch_pool)
    #m = merge([branch1x1, branch3x3, branch5x5, branch_pool_proj], mode='concat', concat_axis=-1)
    from keras.layers import concatenate
    m = concatenate([branch1x1, branch3x3, branch5x5, branch_pool_proj],axis=-1)

    m = AveragePooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), border_mode='valid')(m)
    m = Flatten()(m)
    m = Dropout(0.7)(m)

    # expliciately seperate Dense and Activation layers in order for projecting to structural feature space
    m = Dense(num_labels, activation='linear')(m)
    m = Activation('softmax')(m)

    mod = KM.Model(input=inputs, output=m)

    return mod 
开发者ID:xulabs,项目名称:aitom,代码行数:32,代码来源:subdivide.py

示例4: _Transition

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def _Transition(prev_layer, num_output_features):

    # print('In _Transition')
    x = BatchNormalization()(prev_layer)
    x = Activation('relu')(x)
    x = Conv3D(filters=num_output_features, kernel_size=1, strides=1, use_bias=False, padding='same')(x)
    x = AveragePooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2))(x)
    # print('Completed _Transition')
    return x 
开发者ID:rekon,项目名称:T3D-keras,代码行数:11,代码来源:T3D_keras.py

示例5: define_model

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def define_model(image_shape):
    img_input = Input(shape=image_shape)

    x = Convolution3D(16, 3, 3, 3, subsample=(1, 1, 1), border_mode='same')(img_input)

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

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

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

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

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

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

    x = AveragePooling3D(pool_size=(3, 3, 3), strides=(2, 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 
开发者ID:mdai,项目名称:kaggle-lung-cancer,代码行数:41,代码来源:m10a.py

示例6: define_model

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def define_model(image_shape):
    img_input = Input(shape=image_shape)

    x = Convolution3D(16, 5, 5, 5, subsample=(1, 1, 1), border_mode='same')(img_input)

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

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

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

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

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

    x = AveragePooling3D(pool_size=(4, 4, 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', metrics=['accuracy', 'precision', 'recall', 'fmeasure'])
    model.summary()
    return model 
开发者ID:mdai,项目名称:kaggle-lung-cancer,代码行数:34,代码来源:sd01a.py

示例7: define_model

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def define_model():
    img_input = Input(shape=(64, 64, 64, 1))

    x = Convolution3D(16, 3, 3, 3, subsample=(1, 1, 1), border_mode='same')(img_input)

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

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

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

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

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

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

    x = AveragePooling3D(pool_size=(3, 3, 3), strides=(2, 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 
开发者ID:mdai,项目名称:kaggle-lung-cancer,代码行数:41,代码来源:m10a.py

示例8: define_model

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def define_model():
    img_input = Input(shape=(32, 32, 64, 1))

    x = Convolution3D(16, 5, 5, 5, subsample=(1, 1, 1), border_mode='same')(img_input)

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

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

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

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

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

    x = AveragePooling3D(pool_size=(4, 4, 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 
开发者ID:mdai,项目名称:kaggle-lung-cancer,代码行数:34,代码来源:sd01a.py

示例9: graph_embedding

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def graph_embedding(tensor, n_layers, n_avg_size, n_kernel_size, t_kernel_size, n_max_size, t_max_size):
    """
    Graph embedding.
    :param tensor:
    :param n_layers:
    :return:
    """

    input_shape = K.int_shape(tensor)
    _, n_odes, n_timesteps, side_dim, side_dim, n_channels_in = input_shape

    # hide temporal dimension
    tensor = TransposeLayer((0, 2, 1, 3, 4, 5))(tensor)  # (None, 64, 100, 7, 7, 1024)
    tensor = ReshapeLayer((n_odes, side_dim, side_dim, n_channels_in))(tensor)

    # pool over node
    tensor = AveragePooling3D(pool_size=(n_avg_size, 1, 1), name='pool_n')(tensor)
    _, n_odes, side_dim, side_dim, n_channels_in = K.int_shape(tensor)

    # recover node dimension
    tensor = ReshapeLayer((n_timesteps, n_odes, side_dim, side_dim, n_channels_in))(tensor)  # (None, 64, 100, 7, 7, 1024)
    tensor = TransposeLayer((0, 2, 1, 3, 4, 5))(tensor)  # (None, 100, 64, 7, 7, 1024)

    # hide the node dimension
    tensor = ReshapeLayer((n_timesteps, side_dim, side_dim, n_channels_in))(tensor)  # (None, 64, 7, 7, 1024)

    # 2 layers spatio-temporal conv
    for i in range(n_layers):
        layer_id = '%d' % (i + 1)

        # spatial conv
        tensor = Conv3D(n_channels_in, (1, 1, 1), padding='SAME', name='conv_s_%s' % (layer_id))(tensor)  # (None, 64, 7, 7, 1024)

        # temporal conv
        tensor = DepthwiseConv1DLayer(t_kernel_size, padding='SAME', name='conv_t_%s' % (layer_id))(tensor)  # (None, 64, 7, 7, 1024)

        # node conv
        tensor = __convolve_nodes(tensor, n_odes, layer_id, n_kernel_size)  # (None, 100, 7, 7, 1024)

        # activation
        tensor = BatchNormalization()(tensor)
        tensor = LeakyReLU(alpha=0.2)(tensor)

        # max_pool over nodes
        tensor = MaxPooling3D(pool_size=(n_max_size, 1, 1), name='pool_n_%s' % (layer_id))(tensor)  # (None, 100, 7, 7, 1024)
        _, n_odes, side_dim, side_dim, n_channels_in = K.int_shape(tensor)

        # get back temporal dimension and hide node dimension
        tensor = ReshapeLayer((n_timesteps, n_odes, side_dim, side_dim, n_channels_in))(tensor)  # (None, 64, 100, 7, 7, 1024)
        tensor = TransposeLayer((0, 2, 1, 3, 4, 5))(tensor)  # (None, 100, 64, 7, 7, 1024)
        tensor = ReshapeLayer((n_timesteps, side_dim, side_dim, n_channels_in))(tensor)  # (None, 64, 7, 7, 1024)

        # max_pool over time
        tensor = MaxPooling3D(pool_size=(t_max_size, 1, 1), name='pool_t_%s' % (layer_id))(tensor)  # (None, 64, 7, 7, 1024)
        _, n_timesteps, side_dim, side_dim, n_channels_in = K.int_shape(tensor)  # (None, 64, 7, 7, 1024)

    # recover nodes dimension
    tensor = ReshapeLayer((n_odes, n_timesteps, side_dim, side_dim, n_channels_in))(tensor)

    return tensor 
开发者ID:noureldien,项目名称:videograph,代码行数:62,代码来源:videograph.py

示例10: get_net

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def get_net(input_shape=(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 1), load_weight_path=None, features=False, mal=False) -> Model:
    inputs = Input(shape=input_shape, name="input_1")
    x = inputs
    x = AveragePooling3D(pool_size=(2, 1, 1), strides=(2, 1, 1), border_mode="same")(x)
    x = Convolution3D(64, 3, 3, 3, activation='relu', border_mode='same', name='conv1', subsample=(1, 1, 1))(x)
    x = MaxPooling3D(pool_size=(1, 2, 2), strides=(1, 2, 2), border_mode='valid', name='pool1')(x)

    # 2nd layer group
    x = Convolution3D(128, 3, 3, 3, activation='relu', border_mode='same', name='conv2', subsample=(1, 1, 1))(x)
    x = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), border_mode='valid', name='pool2')(x)
    if USE_DROPOUT:
        x = Dropout(p=0.3)(x)

    # 3rd layer group
    x = Convolution3D(256, 3, 3, 3, activation='relu', border_mode='same', name='conv3a', subsample=(1, 1, 1))(x)
    x = Convolution3D(256, 3, 3, 3, activation='relu', border_mode='same', name='conv3b', subsample=(1, 1, 1))(x)
    x = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), border_mode='valid', name='pool3')(x)
    if USE_DROPOUT:
        x = Dropout(p=0.4)(x)

    # 4th layer group
    x = Convolution3D(512, 3, 3, 3, activation='relu', border_mode='same', name='conv4a', subsample=(1, 1, 1))(x)
    x = Convolution3D(512, 3, 3, 3, activation='relu', border_mode='same', name='conv4b', subsample=(1, 1, 1),)(x)
    x = MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2), border_mode='valid', name='pool4')(x)
    if USE_DROPOUT:
        x = Dropout(p=0.5)(x)

    last64 = Convolution3D(64, 2, 2, 2, activation="relu", name="last_64")(x)
    out_class = Convolution3D(1, 1, 1, 1, activation="sigmoid", name="out_class_last")(last64)
    out_class = Flatten(name="out_class")(out_class)

    out_malignancy = Convolution3D(1, 1, 1, 1, activation=None, name="out_malignancy_last")(last64)
    out_malignancy = Flatten(name="out_malignancy")(out_malignancy)

    model = Model(input=inputs, output=[out_class, out_malignancy])
    if load_weight_path is not None:
        model.load_weights(load_weight_path, by_name=False)
    model.compile(optimizer=SGD(lr=LEARN_RATE, momentum=0.9, nesterov=True), loss={"out_class": "binary_crossentropy", "out_malignancy": mean_absolute_error}, metrics={"out_class": [binary_accuracy, binary_crossentropy], "out_malignancy": mean_absolute_error})

    if features:
        model = Model(input=inputs, output=[last64])
    model.summary(line_length=140)

    return model 
开发者ID:juliandewit,项目名称:kaggle_ndsb2017,代码行数:46,代码来源:step2_train_nodule_detector.py

示例11: pooling

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling3D [as 别名]
def pooling(layer, layer_in, layerId, tensor=True):
    poolMap = {
        ('1D', 'MAX'): MaxPooling1D,
        ('2D', 'MAX'): MaxPooling2D,
        ('3D', 'MAX'): MaxPooling3D,
        ('1D', 'AVE'): AveragePooling1D,
        ('2D', 'AVE'): AveragePooling2D,
        ('3D', 'AVE'): AveragePooling3D,
    }
    out = {}
    layer_type = layer['params']['layer_type']
    pool_type = layer['params']['pool']
    padding = get_padding(layer)
    if (layer_type == '1D'):
        strides = layer['params']['stride_w']
        kernel = layer['params']['kernel_w']
        if (padding == 'custom'):
            p_w = layer['params']['pad_w']
            out[layerId + 'Pad'] = ZeroPadding1D(padding=p_w)(*layer_in)
            padding = 'valid'
            layer_in = [out[layerId + 'Pad']]
    elif (layer_type == '2D'):
        strides = (layer['params']['stride_h'], layer['params']['stride_w'])
        kernel = (layer['params']['kernel_h'], layer['params']['kernel_w'])
        if (padding == 'custom'):
            p_h, p_w = layer['params']['pad_h'], layer['params']['pad_w']
            out[layerId + 'Pad'] = ZeroPadding2D(padding=(p_h, p_w))(*layer_in)
            padding = 'valid'
            layer_in = [out[layerId + 'Pad']]
    else:
        strides = (layer['params']['stride_h'], layer['params']['stride_w'],
                   layer['params']['stride_d'])
        kernel = (layer['params']['kernel_h'], layer['params']['kernel_w'],
                  layer['params']['kernel_d'])
        if (padding == 'custom'):
            p_h, p_w, p_d = layer['params']['pad_h'], layer['params']['pad_w'],\
                layer['params']['pad_d']
            out[layerId +
                'Pad'] = ZeroPadding3D(padding=(p_h, p_w, p_d))(*layer_in)
            padding = 'valid'
            layer_in = [out[layerId + 'Pad']]
    # Note - figure out a permanent fix for padding calculation of layers
    # in case padding is given in layer attributes
    # if ('padding' in layer['params']):
    #    padding = layer['params']['padding']
    out[layerId] = poolMap[(layer_type, pool_type)](
        pool_size=kernel, strides=strides, padding=padding)
    if tensor:
        out[layerId] = out[layerId](*layer_in)
    return out


# ********** Locally-connected Layers ********** 
开发者ID:Cloud-CV,项目名称:Fabrik,代码行数:55,代码来源:layers_export.py


注:本文中的keras.layers.AveragePooling3D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。