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 Comments

Matt J
Matt J 5 minutes ago
Edited: Matt J 4 minutes ago
We c have no way of knowing what you did. Please attach materials needed to reproduce it.
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.

Sign in to comment.

Answers (1)

Matt J
Matt J about 13 hours ago
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.

4 Comments

Hi, the is the download link of the data folder: data
there is some image with different size, so i used augmentedImageDatastore function to resize them to a unique size !
i uploaded the files in matlab drive: data in matlab drive
You need,
inputSize = [570 714 1];
and
ValidationData=augimdsV,...

Sign in to comment.

Products

Release

R2024a

Asked:

on 1 Mar 2026 at 22:56

Edited:

on 2 Mar 2026 at 16:47

Community Treasure Hunt

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

Start Hunting!