An m-by-n-by-1 image cannot be used as input image in the Fully Convolutional Network FCN ?

Hi, Can you help? I am trying to use the FCN (fully convolutional network) layers for semantic segmentation. Here's the function I used:
lgraph = fcnLayers(InputImageSize, NumberOfClasses);
net = trainNetwork(dstrain,lgraph,options);
Here's the error I got:
Error using trainNetwork (line 184) The training images are of size 256×256×1 but the input layer expects images of size 256×256×3. Error in network_bx (line 114)
My question: I would like to know if FCN layer does not work on m×n×1 or grayscale images. If it does, can you help me to understand why I got the above error when I used images with the size m×m×1?

Answers (2)

I was able to modify the input size in deepNetworkDesigner. No idea what will happen when you try to train it.

14 Comments

I have tried to train again but unfortunately, this error persisted: "The training images are of size 256×256×1 but the input layer expects images of size 256×256×3".
That's because you are still running the training on the original network as opposed to the modified version. Make sure you pass whatever variable you exported the modified network to to trainNetwork.
From the description of the fcnLayers - I can see this: The pixel classification layer only supports RGB images.Maybe this is the reason why it does not work with grayscale images?
But the the pixel classification layer is the output layer, not the input layer. I don't see how the deeper layers can know or care about changes you make to the input layer.
What happened when you trained the modified version of the network?
No, it can' produce the same error. You're still training the original version of the network.
I used the function available in Matlab. Do you have a separate network function?
It's not at all clear how you implemented my suggestion. Did you open lgraph in deepNetworkDesigner? What did you do from that point onward?
That was my suggestion... Did you interpret it differently?
Again, your suggestion did not work, unfortunately. I even exported the modified version and got the following error:
Caused by:
Layer 'conv1_1': Input size mismatch. Size of input to this layer is different from the expected input size.
Inputs to this layer:
from layer 'input' (size 256(S) × 256(S) × 1(C) × 1(B))
In addition, I opened the exported version and did additional modifications and got the following warning:
Unable to set the 'inputSize' property of class "ImageInputLayer" because it is read-only.
If you did it from your side and that it worked well, please let me know.
I opened the exported version and did additional modifications and got the following warning:
I didn't get this warning. Not in deepNetworkDesigner at least.
Did you successfully train the fcn after doing your modifications?
I did not attempt to train. My GPU isn't that great.

Sign in to comment.

yes,sir,may be change the data load,such as
imageSize = [256 256 3];
augimds = augmentedImageDatastore(imageSize,dstrain,'ColorPreprocessing','gray2rgb');

1 Comment

yes,sir,may be use
trainingImages = imageDatastore('train',...
'IncludeSubfolders',true,...
'LabelSource','foldernames','ReadFcn',@data_preporcess);
function data = data_preporcess(file)
data = imread(file);
if ndims(data) == 2
data = cat(3, data, data, data);
end
data = imresize(data, [256 256], 'bilinear');
data = double(data);

Sign in to comment.

Products

Release

R2021b

Asked:

on 7 Dec 2021

Commented:

on 9 Dec 2021

Community Treasure Hunt

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

Start Hunting!