Error forming mini-batch for network input "input". Data interpreted with format "SSCB". To specify a different format, use the InputDataFormats option.
68 次查看(过去 30 天)
显示 更早的评论
I am working on a binary classification of images.the code i am using is as follows.
In short, the 'data' file contains an image as 128*128*2 in its cell. 128 is width, 128 is height and 2 is channel (gmti is a name for channel 1, ref is a name for channel 2).
I have 290 images in total so 'data' is a 290*1 cell. 290 as batch, 128*128 as spece, 2 as channel. (SSCB)
For labels, I simply labeled then as double 0 or 1, and used num2str and converted it into categorical.
the error message is as such.
trainnet:
Error forming mini-batch for network input "input". Data interpreted with format "SSCB". To specify a different format, use the InputDataFormats option.
net_trained = trainnet(data,labels_cat, net,'crossentropy',options);
Cause:
Cell array input supports sequence data only.
I tried changing input layer as sequence and making data format as 128*128*2*290 double. Did not work.
Exactly what is the proper data format should i use?
(Due to file size constraint, data_2 file consists of ones and zeros)
----------------------------------------------------------------------------------------------------------
clear
close all
load data_2.mat
load labels_cat.mat
% imds = imageDatastore(data, 'Labels',labels_cat);
%%
imageSize = [128 128 2];
numClasses = 2;
stackDepth = [3 4 23 3];
numFilters = [64 128 256 512];
net = resnetNetwork(imageSize,numClasses, ...
StackDepth=stackDepth, ...
NumFilters=numFilters);
% analyzeNetwork(net)
% net = replaceLayer(net, 'input', sequenceInputLayer(imageSize));
options = trainingOptions("sgdm", ...
InitialLearnRate=0.01, ...
MaxEpochs=100, ...
Shuffle="every-epoch", ...
Plots="training-progress", ...
InputDataFormats = "SSCB", ...
Verbose=false);
% InputDataFormats = "SSCB", ...
%%
%%
net_trained = trainnet(data,labels_cat, net,'crossentropy',options);
2 个评论
Matt J
2024-8-16,3:04
编辑:Matt J
2024-8-16,3:05
The code that sets up your data doesn't include enough to be run:
for i = 1 : size(gmti, 1)
data{i,1}(:,:,1) = [gmti{i}];
data{i,1}(:,:,2) = [ref{i}];
end
nor is it necessary to give us this part. Just attach a .mat file with selections of data and labels_cat.
采纳的回答
Gayathri
2024-8-16,7:23
I was able to reproduce the error mentioned. Before processing image data with networks like ResNet, it's essential to first convert cell-formatted data into an array.
data1 = zeros(128, 128, 2, 290);
for i = 1:290
data1(:, :, :, i) = data{i};
end
And then when passing the input data to the “trainnet” function for training, the following change can be accommodated.
net_trained = trainnet({data1,labels_cat}, net,'crossentropy',options);
I hope the approach mentioned above will help resolve the issue.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!