Error forming mini-batch for network input

i want to train a cnn with a folder of images with the size [h w c], the imageInputLayerargument is the same size of the images (h w c), but when training the network matlab says:
Error using trainnet (line 46)
Error forming mini-batch for network input "imageinput". Data interpreted with format "SSCB". To specify a
different format, use the InputDataFormats option.
Caused by:
Dimensions of arrays being concatenated are not consistent.

2 件のコメント

Matt J
Matt J 2026 年 3 月 1 日 23:49
編集済み: Matt J 2026 年 3 月 1 日 23:50
We c have no way of knowing what you did. Please attach materials needed to reproduce it.
Walid
Walid 2026 年 3 月 2 日 0:18
Thanks for the replay, this is my code for multiclass (3 classes) classification using CNN based on image files stored in three subfolders in the main folder: data.:
clear all; close all; clc
% Define the path to your main data folder
dataFolder = 'C:\data';
% Create an image datastore
imds = imageDatastore(dataFolder, ...
'IncludeSubfolders', true, ...
'LabelSource', 'foldernames');
% View the class names and the number of images per class
%imds=aug_imds;
labelCount = countEachLabel(imds);
disp(labelCount);
% Split the datastore into training and validation sets (e.g., 70% for training, 30% for validation)
[imdsTrain, imdsValidation] = splitEachLabel(imds, 0.7, 'randomized');
inputSize = [570 714 3];
augimdsT = augmentedImageDatastore(inputSize,imdsTrain,'ColorPreprocessing','rgb2gray');
augimdsV = augmentedImageDatastore(inputSize,imdsValidation,'ColorPreprocessing','rgb2gray');
numClasses = 3;
layers = [
imageInputLayer(inputSize)
convolution2dLayer(5,5)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
%
options = trainingOptions("sgdm", ...
MaxEpochs=4, ...
ValidationData=imdsValidation, ...
ValidationFrequency=30, ...
Plots="training-progress", ...
Metrics="accuracy", ...
Verbose=false);
% train
net = trainnet(augimdsT,layers,"crossentropy",options);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I receive the following message:
Error forming validation data mini-batch.
Caused by:
Error forming mini-batch for network input "imageinput". Data interpreted with format "SSCB". To specify
a different format, use the InputDataFormats option.
Dimensions of arrays being concatenated are not consistent.

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2026 年 3 月 2 日 3:23

1 投票

This is not enough to reproduce the error. You haven't provided input images. My guess, however, is that there are some files in C:\data that are not 570x714x3.

8 件のコメント

Walid
Walid 2026 年 3 月 2 日 9:39
Hi, the is the download link of the data folder: data
Walid
Walid 2026 年 3 月 2 日 11:40
there is some image with different size, so i used augmentedImageDatastore function to resize them to a unique size !
Walid
Walid 2026 年 3 月 2 日 11:43
i uploaded the files in matlab drive: data in matlab drive
Matt J
Matt J 2026 年 3 月 2 日 16:25
編集済み: Matt J 2026 年 3 月 2 日 16:47
You need,
inputSize = [570 714 1];
and
ValidationData=augimdsV,...
Walid
Walid 約22時間 前
Thank you for the response,
performing the code, Matlab return this error:
Error using trainnet (line 46)
Unable to apply function specified by 'MiniBatchFcn' value.
Error in march (line 47)
net = trainnet(imdsTrain,layers,"crossentropy",options);
Caused by:
Error using deep.internal.train.createMiniBatch (line 22)
Error forming mini-batch for network input "imageinput". Data interpreted with format "SSCB". To specify
a different format, use the InputDataFormats option.
Dimensions of arrays being concatenated are not consistent.
my code is attached. in this Link
Matt J
Matt J 約17時間 前
編集済み: Matt J 約17時間 前
your link goes to new code. However, your original code, as presented in your question, should be working now with the changes I propose above. If the code is working for you as well, please Accept-click the answer to indicate that the question is resolved.
As for the new code, it is pretty clear why it doesn't work. You removed the resizing done by the augmentedDatastores so, per our discussion above, it is not going to be possible to concatenate them.
Walid
Walid 約15時間 前
the original code does'nt work ! the same error !
Matt J
Matt J 約9時間 前
編集済み: Matt J 約9時間 前
It works for me. Did you incorporate my fixes?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImage Data Workflows についてさらに検索

製品

リリース

R2024a

質問済み:

2026 年 3 月 1 日 22:56

編集済み:

約9時間 前

Community Treasure Hunt

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

Start Hunting!

Translated by