Errors compiling some of the Pretrained Networks

1 view (last 30 days)
Hi,
I have been trying to use pretrained networks with my own data. I have accomplished to use with vgg16, vgg19 and alexnet. However, I couldn't use any other networks. When I want to use, i received errors as can be seen in the following part.
Error using trainNetwork (line 184)
Invalid network.
Error in CNN_classification (line 136)
netTransfer = trainNetwork(augTrain,layers,options);
Caused by:
Layer 'concatenate_1': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'concatenate_2': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'conv2d_7': Input size mismatch. Size of input to this layer is different from the expected input size.
Inputs to this layer:
from layer 'activation_9_relu' (size 35(S) × 35(S) × 64(C) × 1(B))
Layer 'mixed0': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed1': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed10': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed2': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed3': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed4': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed5': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed6': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed7': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed8': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed9': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed9_0': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'mixed9_1': Unconnected input. Each layer input must be connected to the output of another layer.
I wrote my own script for my implementations and also I used the Deep Network Designer app to export networks. Both are not working for me. I also read about DAGNetworks might require the usage of layergraph command in training command. Despite I used that, still not working.
% netTransfer = trainNetwork(augTrain,layers,options);
netTransfer = trainNetwork(augTrain,layerGraph(layers),options);
I would appreciate if anyone can help me.
Thanks in advance!

Answers (1)

Milan Bansal
Milan Bansal on 27 Mar 2024
Hi Akaydin
I understand that you are facing multiple errors when trying to train a convolutional neural network (CNN) using trainNetwork in MATLAB. The errors indicate issues with unconnected inputs in several layers and an input size mismatch for the 'conv2d_7' layer.
Unconnected Input Errors:
  • These errors occur when a layer expected to receive inputs is not connected to any previous layer's output.
  • To fix this, review your model architecture and ensure that every layer mentioned in the error messages ('concatenate_1', 'concatenate_2', 'mixed0', 'mixed9_1', etc.) is correctly receiving input from the appropriate layers. In complex architectures, it is important to map out the connections or use a diagram to track how layers should be connected.
Input Size Mismatch Error:
  • The 'conv2d_7' layer is expecting an input size different from what it's receiving from the 'activation_9_relu' layer. This generally happens due to incorrect configuration of the layer's parameters, such as the number of filters, kernel size, stride, or padding, which affects the output size of the previous layers.
  • To resolve this, you need to adjust the 'conv2d_7' layer's parameters or the preceding layer's parameters to ensure the output size of the 'activation_9_relu' layer matches the expected input size of the 'conv2d_7' layer.
Please refer to the following steps to address the issue:
  1. Open MATLAB's Deep Network Designer application and import your model. All the layers present in the model will be displayed in the form of blocks and connections.
  2. Click on "Analyze Network" from the toolbar.
  3. The Network Analyzer window will appear. All the problematic layers will be shown as errors in the Network Analyzer window. Navigate to those layers one by one.
  4. Make sure that the layers corresponding to the "Unconnected Input Errors" have valid connections. If not, make proper connections according to your expected model architecture. Make sure that no block in the network is left unconnected.
  5. For layers related to "Input Size Mismatch Error," i.e., 'conv2d_7', change the parameters such as the number of filters, stride value, padding, etc. according to the output size of the preceding layer.
  6. Analyze the network using the Network Analyzer and make sure all the errors are resolved.
  7. Export the model to the workspace.
Please refer to the following documentation link to learn more about the "Deep Network Designer".
Hope this helps.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!