Python keras.layers.convolutional 模块,ZeroPadding3D() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用keras.layers.convolutional.ZeroPadding3D()

项目:DeepST    作者:lucktroy    | 项目源码 | 文件源码
def seq3DCNN(n_flow=4, seq_len=3, map_height=32, map_width=32):
    model=Sequential()
    # model.add(ZeroPadding3D(padding=(0, 1, 1), input_shape=(n_flow, seq_len, map_height, map_width)))
    # model.add(Convolution3D(64, 2, 3, 3, border_mode='valid'))
    model.add(Convolution3D(64, 2, 3, 3, border_mode='same', input_shape=(n_flow, seq_len, map_height, map_width)))
    model.add(Activation('relu'))

    model.add(Convolution3D(128, 2, 3, 3, border_mode='same'))
    model.add(Activation('relu'))

    model.add(Convolution3D(64, 2, 3, 3, border_mode='same'))
    model.add(Activation('relu'))

    model.add(ZeroPadding3D(padding=(0, 1, 1)))
    model.add(Convolution3D(n_flow, seq_len, 3, 3, border_mode='valid'))
    # model.add(Convolution3D(n_flow, seq_len-2, 3, 3, border_mode='same'))
    model.add(Activation('tanh'))
    return model
项目:keras    作者:GeekLiB    | 项目源码 | 文件源码
def test_zero_padding_3d():
    nb_samples = 2
    stack_size = 2
    input_len_dim1 = 4
    input_len_dim2 = 5
    input_len_dim3 = 3

    input = np.ones((nb_samples,
                     input_len_dim1, input_len_dim2, input_len_dim3,
                     stack_size))

    # basic test
    layer_test(convolutional.ZeroPadding3D,
               kwargs={'padding': (2, 2, 2)},
               input_shape=input.shape)

    # correctness test
    layer = convolutional.ZeroPadding3D(padding=(2, 2, 2))
    layer.build(input.shape)
    output = layer(K.variable(input))
    np_output = K.eval(output)
    for offset in [0, 1, -1, -2]:
        assert_allclose(np_output[:, offset, :, :, :], 0.)
        assert_allclose(np_output[:, :, offset, :, :], 0.)
        assert_allclose(np_output[:, :, :, offset, :], 0.)
    assert_allclose(np_output[:, 2:-2, 2:-2, 2:-2, :], 1.)
    layer.get_config()
项目:keras-customized    作者:ambrite    | 项目源码 | 文件源码
def test_zero_padding_3d():
    nb_samples = 2
    stack_size = 2
    input_len_dim1 = 4
    input_len_dim2 = 5
    input_len_dim3 = 3

    input = np.ones((nb_samples,
                     input_len_dim1, input_len_dim2, input_len_dim3,
                     stack_size))

    # basic test
    layer_test(convolutional.ZeroPadding3D,
               kwargs={'padding': (2, 2, 2)},
               input_shape=input.shape)

    # correctness test
    layer = convolutional.ZeroPadding3D(padding=(2, 2, 2))
    layer.build(input.shape)
    output = layer(K.variable(input))
    np_output = K.eval(output)
    for offset in [0, 1, -1, -2]:
        assert_allclose(np_output[:, offset, :, :, :], 0.)
        assert_allclose(np_output[:, :, offset, :, :], 0.)
        assert_allclose(np_output[:, :, :, offset, :], 0.)
    assert_allclose(np_output[:, 2:-2, 2:-2, 2:-2, :], 1.)
    layer.get_config()
项目:keras    作者:NVIDIA    | 项目源码 | 文件源码
def test_zero_padding_3d():
    nb_samples = 2
    stack_size = 2
    input_len_dim1 = 4
    input_len_dim2 = 5
    input_len_dim3 = 3

    input = np.ones((nb_samples,
                     input_len_dim1, input_len_dim2, input_len_dim3,
                     stack_size))

    # basic test
    layer_test(convolutional.ZeroPadding3D,
               kwargs={'padding': (2, 2, 2)},
               input_shape=input.shape)

    # correctness test
    layer = convolutional.ZeroPadding3D(padding=(2, 2, 2))
    layer.build(input.shape)
    output = layer(K.variable(input))
    np_output = K.eval(output)
    for offset in [0, 1, -1, -2]:
        assert_allclose(np_output[:, offset, :, :, :], 0.)
        assert_allclose(np_output[:, :, offset, :, :], 0.)
        assert_allclose(np_output[:, :, :, offset, :], 0.)
    assert_allclose(np_output[:, 2:-2, 2:-2, 2:-2, :], 1.)
    layer.get_config()
项目:c3d-keras    作者:axon-research    | 项目源码 | 文件源码
def get_model(summary=False, backend='tf'):
    """ Return the Keras model of the network
    """
    model = Sequential()
    if backend == 'tf':
        input_shape=(16, 112, 112, 3) # l, h, w, c
    else:
        input_shape=(3, 16, 112, 112) # c, l, h, w
    model.add(Convolution3D(64, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv1',
                            input_shape=input_shape))
    model.add(MaxPooling3D(pool_size=(1, 2, 2), strides=(1, 2, 2),
                           border_mode='valid', name='pool1'))
    # 2nd layer group
    model.add(Convolution3D(128, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv2'))
    model.add(MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2),
                           border_mode='valid', name='pool2'))
    # 3rd layer group
    model.add(Convolution3D(256, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv3a'))
    model.add(Convolution3D(256, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv3b'))
    model.add(MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2),
                           border_mode='valid', name='pool3'))
    # 4th layer group
    model.add(Convolution3D(512, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv4a'))
    model.add(Convolution3D(512, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv4b'))
    model.add(MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2),
                           border_mode='valid', name='pool4'))
    # 5th layer group
    model.add(Convolution3D(512, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv5a'))
    model.add(Convolution3D(512, 3, 3, 3, activation='relu',
                            border_mode='same', name='conv5b'))
    model.add(ZeroPadding3D(padding=((0, 0), (0, 1), (0, 1)), name='zeropad5'))
    model.add(MaxPooling3D(pool_size=(2, 2, 2), strides=(2, 2, 2),
                           border_mode='valid', name='pool5'))
    model.add(Flatten())
    # FC layers group
    model.add(Dense(4096, activation='relu', name='fc6'))
    model.add(Dropout(.5))
    model.add(Dense(4096, activation='relu', name='fc7'))
    model.add(Dropout(.5))
    model.add(Dense(487, activation='softmax', name='fc8'))

    if summary:
        print(model.summary())

    return model