Training a Convolutional Autoencoder

10 visualizaciones (últimos 30 días)
Aghata
Aghata el 23 de Mayo de 2024
Respondida: ali kaffashbashi el 17 de Oct. de 2024
I'm trying to train this simple convolutional autoencoder but I'm getting error on the training part. The error says the size of predictions and tragets are not the same. But When I check the network structure using the analyseNetwork function it seems that my input has the same size as my output. I can't find where is the error. Can someone help me?
Follows the code
datastore_MP = datastore("Tiles_MP1_100ov50\", "IncludeSubfolders",true, "LabelSource","foldernames");
images_MP = cell(numel(datastore_MP.Files), 1);
for i = 1:numel(datastore_MP.Files)
img_MP = readimage(datastore_MP, i);
[rows, cols] = size(img_MP);
images_MP{i} = img_MP;
end
encoderBlock = @(block) [
convolution2dLayer(3,2^(3+block), "Padding",'same')
reluLayer
maxPooling2dLayer(2,"Stride",2)
convolution2dLayer(3,2^(5+block), "Padding",'same')
reluLayer
maxPooling2dLayer(2,"Stride",2)];
net_E = blockedNetwork(encoderBlock,1,"NamePrefix","encoder_");
decoderBlock = @(block) [
transposedConv2dLayer(3,2^(5-block),"Stride",2)
reluLayer
transposedConv2dLayer(3,2^(1-block), "Stride",2)
reluLayer];
net_D = blockedNetwork(decoderBlock,1,"NamePrefix","decoder_");
inputSize = [100 100 1];
CAE = encoderDecoderNetwork(inputSize,net_E,net_D);
analyzeNetwork(CAE)
options = trainingOptions( "adam",...
"Plots","training-progress",...
"MaxEpochs", 100,...
"L2Regularization",0.001);
trainedCAE = trainnet(datastore_MP, CAE, "mse", options);

Respuestas (2)

newhere
newhere el 23 de Mayo de 2024
Hey, try changing 'trainnet' to 'trainNetwork'.
trainedCAE = trainNetwork(datastore_MP, CAE, "mse", options);
  1 comentario
Aghata
Aghata el 27 de Mayo de 2024
Hello, Fatma.
I tried but this doesn't fix the problem. I've been trying to find a way to set the target size to be the same as the input or output, but without success.

Iniciar sesión para comentar.


ali kaffashbashi
ali kaffashbashi el 17 de Oct. de 2024
I guess it tries to set your label sources (the folder names) as targets during the training. Hence, the input and output sizes become different. I reckon using the following code instead of your training line will solve your problem:
trainedCAE = trainnet(combine(datastore_MP,datastore_MP), CAE, "mse", options);

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by