You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多分类CNN实现求助:Keras网络输出形状与论文不符

Troubleshooting Mismatched Output Shapes in Your Keras Network

Hey there! Since you're new to Keras and Python, let's break down why your network's output shapes don't match the specs from the paper. I'll walk through the key issues in your code and how to fix them.

Key Issues to Fix

1. Max Pooling Padding is Missing

Looking at your code, you're using MaxPooling2D with the default padding='valid'—this is the main culprit behind shrinking output shapes.

When you use a 3×3 pool window with stride 1 and valid padding, each pooling layer reduces the spatial dimensions by pool_size - stride (3-1=2), which is why your output goes from (128,43) → (126,41) → (124,39), etc.

Most likely, the paper uses same padding for max pooling (matching the convolution layers' padding), which keeps the spatial dimensions identical to the input.

2. Double-Check Filter Number Timing (Minor)

Your logic for doubling filter counts after each pool/dropout step looks correct, but just confirm the paper specifies doubling filters after each block of two convolutions and pooling—this part seems aligned, but it's worth a quick cross-check.

Fixes to Implement

Update Max Pooling Layers

Modify your MaxPooling2D lines to include padding='same':

model.add(MaxPooling2D(pool_size=maxpoolSize, strides=maxpoolStride, padding='same'))

Verify Input Shape Match

Double-check that the paper's input shape matches your (128,43,1)—if the paper uses a different input size, that'll also throw off output shapes, but assuming your input is correct, the padding fix should resolve most mismatches.

What to Expect After Fixes

After updating the padding, each pooling layer will preserve the spatial dimensions. For example:

  • After the first pool: Output shape stays (128,43,32) instead of shrinking to (126,41,32)
  • By the final convolution block, your output shape will match the spatial dimensions listed in the paper's Table I
  • The global max pooling step will still produce a 256-dimensional vector, which feeds into your dense layers correctly

Give these changes a run, then check model.summary() again—your output shapes should now align with the paper's specifications. If you still see discrepancies, let's dig deeper into the paper's exact layer specs!

内容的提问来源于stack exchange,提问作者skateskate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:22:31