how to performe unpooling in U shaped network?
    6 views (last 30 days)
  
       Show older comments
    
I want to classify an image and reconstruct the classification image of same size as of input. To do so i choose to make a u shaped network with convolution relu and pooling layers. while unpooling i am getting invalid network error. What will be the correct network layer?? Layer network which i have created is as
 layers =  [imageInputLayer([100 100 3])
          convolution2dLayer(5,10)
          reluLayer
          maxPooling2dLayer(2,'Stride',2)
          convolution2dLayer(5,10)
          reluLayer
          maxPooling2dLayer(2,'Stride',2)
          dropoutLayer
          maxUnpooling2dLayer
          reluLayer
          convolution2dLayer(5,10)
          maxUnpooling2dLayer
          reluLayer
          convolution2dLayer(5,10)
          softmaxLayer
          classificationLayer];
0 Comments
Answers (1)
  Gayathri
 on 10 Jun 2025
        
      Edited: Gayathri
 on 10 Jun 2025
  
      To create a U-shaped network for image classification and reconstruction, you need to ensure that the layers used for upsampling (unpooling) are correctly configured. The error you are encountering with maxUnpooling2dLayer likely arises from not having the corresponding pooling layers that store the indices required for unpooling.
Here’s a corrected version of your network architecture that includes the necessary pooling and unpooling layers:
layers = [
    imageInputLayer([100 100 3])
    convolution2dLayer(5, 10, 'Padding', 'same')
    reluLayer
    maxPooling2dLayer(2, 'Stride', 2, 'Name', 'pool1')
    convolution2dLayer(5, 10, 'Padding', 'same')
    reluLayer
    maxPooling2dLayer(2, 'Stride', 2, 'Name', 'pool2')
    dropoutLayer
    % Bottleneck layer (optional)
    convolution2dLayer(5, 10, 'Padding', 'same')
    reluLayer
    % Unpooling layers
    transposedConv2dLayer(2, 10, 'Stride', 2, 'Cropping', 'same', 'Name', 'unpool1')
    reluLayer
    transposedConv2dLayer(2, 10, 'Stride', 2, 'Cropping', 'same', 'Name', 'unpool2')
    reluLayer
    convolution2dLayer(5, 3, 'Padding', 'same') % Adjust output channels as needed
    softmaxLayer
    classificationLayer
];
Use of transposedConv2dLayer: Instead of maxUnpooling2dLayer, which requires specific indices from the pooling layers, I have replaced it with transposedConv2dLayer. This layer is commonly used for upsampling in U-Net architectures.
Always validate the architecture by plotting it using analyzeNetwork(layers) to ensure that the dimensions are consistent throughout the network.
This architecture should help you avoid the invalid network error and achieve your goal of classifying and reconstructing the image.
For more information on "transposedConv2dLayer", refer to the following documentation link.
From MATLAB R2024a, we can use the "unet" function, which will serve the purpose for which you are using the custom layers. 
You can look into the documentation and modify the parameters to modify the architecture to your needs.
0 Comments
See Also
Categories
				Find more on Deep Learning Toolbox in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
