Error forming mini-batch for network input "input". Data interpreted with format "SSCB". To specify a different format, use the InputDataFormats option.
49 次查看(过去 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 个评论
采纳的回答
Gayathri
2024-8-16
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!