python - Keras - CNN 模型总结维度解读

标签 python deep-learning keras convolution

我正在使用 Keras 库构建此深度学习模型:INPUT(深度=1, 高度=15, 宽度=27) -> CONV[深度=8](高度=4, 宽度=27) -> POOL(高度=2,宽度=1)->(回归)输出。

我期望 volving2d_1 的输出形状为 (None, 8, 12, 1),因此,pooling2d_1 的输出形状为 (None, 8, 6, 1);而我分别得到 (None, 8, 15, 27) 和 (None, 8, 7, 27) 。

我在这里做了什么或解释错误了什么?

P.S.:此外,此设置会产生基线错误:99.23%!

print "SHAPE OF INPUT IS:", num_train_3D, depth, height, width
inp = Input(shape=(depth, height, width)) 
conv_1 = Convolution2D(8, 4, 27, border_mode='same', activation='relu')(inp)
pool_1 = MaxPooling2D(pool_size=(2, 1))(conv_1)
''' Now flatten to 1D, apply FC -> ReLU (with dropout) -> softmax '''
flat = Flatten()(pool_1)
out = Dense(1)(flat)  #regression

model = Model(input=inp, output=out) # To define a model, just specify its input and output layers

print "Model Summary:"
print model.summary()

========================================

SHAPE OF INPUT IS: 53745 1 15 27
Model Summary:
____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
input_1 (InputLayer)             (None, 1, 15, 27)     0                                            
____________________________________________________________________________________________________
convolution2d_1 (Convolution2D)  (None, 8, 15, 27)     872         input_1[0][0]                    
____________________________________________________________________________________________________
maxpooling2d_1 (MaxPooling2D)    (None, 8, 7, 27)      0           convolution2d_1[0][0]            
____________________________________________________________________________________________________
flatten_1 (Flatten)              (None, 1512)          0           maxpooling2d_1[0][0]             
____________________________________________________________________________________________________
dense_1 (Dense)                  (None, 1)             1513        flatten_1[0][0]                  
====================================================================================================
Total params: 2,385
Trainable params: 2,385
Non-trainable params: 0

最佳答案

border_mode='same' 更改为 border_mode='valid'。边框模式 same 向输入添加零填充,以确保卷积层的输出与其输入具有相同的形状。使用边界模式有效仅在输入和滤波器完全重叠的地方执行卷积。

关于python - Keras - CNN 模型总结维度解读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41869984/

相关文章:

c++ - 通过网络直接从另一台计算机的内存中读取文件

python - 我如何让 keras 预测 one-hot 矩阵以外的东西?

machine-learning - 如何在 Keras 中训练暹罗网络?

python - 使用 GUI 从 Python 代码运行 dask 调度程序

python - 扩展新用户创建表单,Django

tensorflow - 使用 TensorFlow 对象检测 API 模型进行预测

python - 哪种是进行图像标准化的正确方法?

python - 使用函数式 API 进行迁移学习和量化感知训练

python - python 中的半唯一元组? (又名。元组主键?)

python - 如何使用 SQLAlchemy 在 MySQL 中创建数据库?