Semantic Segmentation on time series data using Sentinel 1 data: Error Using Trainnet()
古いコメントを表示
I need some product support on using the trainnet() function. Based on documentation, I'm expecting to be able to feed trainnet() an argument of double(SxSxCxB) as a Predictor and type catagorical(SxSxCxB). Instead, I'm encountering an size mismatch error between the network and the data. Some details to reproduce the error are below. Thanks for your support!
Here is some bare bones code that generates the unexpected error:
Image = zeros(256, 256, 1, 5656); % Predictor
Label = zeros(256, 256, 1, 5656); % Target
This yields dimensions of [256 256 1 5656] for each array.
Then the arrays are converted to an argument for the input layer.
Image = dlarray(Image,"SSCB"); % Preferred "SSCBT", but may not be necessary
Label = categorical(dlarray(Label, "SSCB"));
A Bare Bones Network is defined for demonstration:
inputLayer = imageInputLayer([256, 256, 1], Name = 'input',Normalization = 'none');
% Convolutional Layer 1: 3x3 kernel, 32 filters, stride 1, padding 1
conv1 = convolution2dLayer(3, 32, 'Stride', 1, 'Padding', 1, 'Name', 'conv1');
batchNorm1 = batchNormalizationLayer('Name', 'bn1');
relu1 = reluLayer('Name', 'relu1');
% Max-pooling Layer 1: 2x2 pooling with stride 2
maxPool1 = maxPooling2dLayer(2, 'Stride', 2, 'Name', 'maxPool1');
% Convolutional Layer 2: 3x3 kernel, 64 filters, stride 1, padding 1
conv2 = convolution2dLayer(3, 64, 'Stride', 1, 'Padding', 1, 'Name', 'conv2');
batchNorm2 = batchNormalizationLayer('Name', 'bn2');
relu2 = reluLayer('Name', 'relu2');
% Max-pooling Layer 2: 2x2 pooling with stride 2
maxPool2 = maxPooling2dLayer(2, 'Stride', 2, 'Name', 'maxPool2');
% Fully Connected Layer: 256 units
fc1 = fullyConnectedLayer(256, 'Name', 'fc1');
relu3 = reluLayer('Name', 'relu3');
% Fully Connected Layer for classification: 10 output classes
fc2 = fullyConnectedLayer(10, 'Name', 'fc2');
% Softmax Layer: Converts the final output into class probabilities
softmaxLayer = softmaxLayer('Name', 'softmax');
% Classification Layer: The output is compared with the true labels
classificationLayer = classificationLayer('Name', 'classOutput');
% Combine all layers into the network
layers = [
inputLayer
conv1
batchNorm1
relu1
maxPool1
conv2
batchNorm2
relu2
maxPool2
fc1
relu3
fc2
softmaxLayer
% classificationLayer
];
We can then define and observe the network:
%% Define the network
clear inputLayer batchNorm1 batchNorm2 classificationLayer conv1 conv2 fc1 fc2 maxPool1 maxPool2 relu1 relu2 relu3 softmaxLayer
bbnet = dlnetwork(layers);
analyzeNetwork(bbnet)
%% Train the network
options = trainingOptions('adam', 'MaxEpochs', 5, 'MiniBatchSize', 64, 'Plots', 'training-progress');
lossFcn = "crossentropy";
net = trainnet(Image, Label, bbnet, lossFcn, options);
Error using trainnet (line 54)
Number of observations in predictors (1) and targets (256) must match. Check that the data and network are
consistent.
Error in BareBonesDLConcepts (line 4)
net = trainnet(Image, Label, bbnet, lossFcn, options);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The documentation around the trainnet() function makes me think that this should work. Any thoughts?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Semantic Segmentation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


