Error when using convolution2dLayer between connected maxPooling2dLayer and maxUnpooling2dLayer

3 ビュー (過去 30 日間)
I'm trying to create a modified UNet using connected max pooling and max unpooling layers. However, if I put a convolution layer between the pooling and unpooling layers, the network isn't valid. The error is reported for the unpooling layer:
Input size mismatch. Size of input to this layer is different from the expected input size.
The sizes for the CONV layer, MAXPOOL indices, and MAXPOOL size inputs are all different. Minimum working example below. Am I missing something obvious, or is it not possible to use other layers between maxpool and maxunpool?
% define layers
layers = [
imageInputLayer([128, 128], 'Name', 'INPUTLAYER')
maxPooling2dLayer([2 2], 'HasUnpoolingOutputs', true, 'Stride', [2 2], 'Name', 'MAXPOOL')
convolution2dLayer([3 3], 32, 'Padding', 'same', 'Stride', [1 1], 'Name', 'CONV')
maxUnpooling2dLayer('Name', 'UNPOOL')
regressionLayer('Name', 'MSE')
];
% define network
lgraph = layerGraph(layers);
% define connections
lgraph = connectLayers(lgraph, 'MAXPOOL/indices', 'UNPOOL/indices');
lgraph = connectLayers(lgraph, 'MAXPOOL/size', 'UNPOOL/size');
% plot and check
analyzeNetwork(lgraph);

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 6 月 29 日
You convolution layer is changing the number of channels in the output after the max pooling.
This causes the input size mismatch. You need to match the number of channels output by convolution layer to the output by maxpooling layer.
% define layers
layers = [
imageInputLayer([128, 128], 'Name', 'INPUTLAYER')
maxPooling2dLayer([2 2], 'HasUnpoolingOutputs', true, 'Stride', [2 2], 'Name', 'MAXPOOL')
convolution2dLayer([3 3], 1, 'Padding', 'same', 'Stride', [1 1], 'Name', 'CONV')
maxUnpooling2dLayer('Name', 'UNPOOL')
regressionLayer('Name', 'MSE')
];
% define network
lgraph = layerGraph(layers);
% define connections
lgraph = connectLayers(lgraph, 'MAXPOOL/indices', 'UNPOOL/indices');
lgraph = connectLayers(lgraph, 'MAXPOOL/size', 'UNPOOL/size');
% plot and check
analyzeNetwork(lgraph);
  1 件のコメント
Bradley Treeby
Bradley Treeby 2020 年 6 月 29 日
Thanks! This pointed me to the problem in my complete code - my index to link the number of channels in the different encoding and decoding levels was offset by one.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by