【问题标题】:Keras - CNN Model Summary Diemension InterpretationKeras - CNN 模型摘要维度解释
【发布时间】:2023-03-30 01:50:01
【问题描述】:

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

我希望卷积 2d_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

【问题讨论】:

    标签: python deep-learning keras convolution


    【解决方案1】:

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

    【讨论】:

    • 谢谢,确实解决了尺寸不匹配问题;但是你能评论一下那个 99.23% 的基线错误吗,我仍然得到完全相同的结果!
    • 在没有任何细节的情况下很难说出错误。您是在谈论训练错误还是测试错误?你的数据集呢?提供一个最小的可重现示例和所有必要的细节,以获得有关错误问题的建设性反馈。我建议在一个新问题中这样做,这个问题是关于维度的。
    • 当然,我会自己尝试一段时间,如果需要,我会这样做:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多