Azzera filtri
Azzera filtri

On performing regression tasks from spectral imaging data

1 visualizzazione (ultimi 30 giorni)
I would like to be informed about the modifications.
I would like to create a model using deep learning to predict concentration from spectra, using spectral mapping data and the concentration of the three components at each measurement point as the original data.
I have written the following code, but I get the following error
Error while using: trainNetwork
Invalid training data. The output size (3) of the last layer does not match the response size (100).
Error: layer_test (line 86)
net = trainNetwork(xTrain, yTrain, layers, options);
The original data for spectral mapping is 100pixel x 100pixel x 380 channels.
I do not understand why the response is 100 and would appreciate your advice, including whether such a task might be possible.
% read .dm3 files
[~, ximage1] = dmread('P4.dm3');
% set the data ranges for processing
xdim = 100;
ydim = 100;
zdim = 380;
row = xdim*ydim;
% Expand SI data to 2D matrices
xdat1 = squeeze(ximage1(1:xdim, 1:ydim, 1:zdim));
xdat1_reshape = reshape(xdat1, [row,zdim]);
% Load labels (C1, C2, C3)
C1 = readmatrix('C1.txt');
C2 = readmatrix('C2.txt');
C3 = readmatrix('C3.txt');
% Extract the desired range from C1, C2, C3
C1 = C1(1:xdim, 1:ydim);
C1_reshape = reshape(C1,[row,1]);
C2 = C2(1:xdim, 1:ydim);
C2_reshape = reshape(C2,[row,1]);
C3 = C3(1:xdim, 1:ydim);
C3_reshape = reshape(C3,[row,1]);
C = cat(3, C1, C2, C3); % 出
% network
layers = [
sequenceInputLayer([100, 100, 380])
convolution2dLayer(3, 16, 'Padding', 'same')
maxPooling2dLayer(2, 'Stride', 2)
convolution2dLayer(3, 32, 'Padding', 'same')
maxPooling2dLayer(2, 'Stride', 2)
flattenLayer() % to 1d
lstmLayer(20, 'OutputMode', 'last') % LSTM)
regressionLayer('Name', 'output')
% option setting
options = trainingOptions('adam', 'MaxEpochs', 10, 'MiniBatchSize', 32);
% data prep.
xTrain = xdat1;
yTrain = C;
net = trainNetwork(xTrain, yTrain, layers, options);

Risposte (1)

Shreeya il 20 Feb 2024
From the error message, it seems that the output size of the neural network is inconsistent with the expected response size. You can approach this problem by changing the number of neurons in the last layer. Also, refer to this link for more help:




Community Treasure Hunt

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

Start Hunting!

Translated by