I wrote a script in Matlab 2021b for Deep learning using CNN for Classification Parkinson disease Patients from their voices data which located in three folders contains (mild, moderate, and severe) respectively of Parkinson patients' audio files of .wav format, all audio files in these folders are of sample rate of 22050 khz and 2.2 seconds length. The code below after Run giving error as folllows: File: imageInputLayer.m Line: 1 Column: 34 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. Error in mm1 (line 39) imageInputLayer([48510, 1, 1], 'Normalization', 'zscore', 'Name', 'input') Below the code of classification Parkinson patients from their voices ensuring normalizing audio data and ensuring audioData matrix and labels are appropriately shaped for the CNN model.
% Set the paths to your data folders
dataFolder = fullfile(tempdir, "DataSet");
% Load the dataset
mildFolder = fullfile(dataFolder, 'MDN');
moderateFolder = fullfile(dataFolder, 'MEN');
severeFolder = fullfile(dataFolder, 'SEN');
% Load data from folders
mildData = loadAudioData(mildFolder);
moderateData = loadAudioData(moderateFolder);
severeData = loadAudioData(severeFolder);
% Concatenate data and labels
audioData = cat(4, mildData, moderateData, severeData);
labels = categorical([repmat({'mild'}, 1, numel(mildData)), ...
repmat({'moderate'}, 1, numel(moderateData)), ...
repmat({'severe'}, 1, numel(severeData))]);
% Shuffle the data
idx = randperm(size(audioData, 4));
audioData = audioData(:, :, :, idx);
labels = labels(idx);
% Split data into training and testing sets
splitRatio = 0.8;
splitIdx = round(splitRatio * numel(labels));
% Assuming your audio data is a sequence of length 48510 with one channel
trainData = reshape(audioData(:, :, :, 1:splitIdx), [48510, 1, 1, splitIdx]);
trainLabels = labels(1:splitIdx);
testData = reshape(audioData(:, :, :, splitIdx+1:end), [48510, 1, 1, numel(labels)-splitIdx]);
testLabels = labels(splitIdx+1:end);
% Define the CNN model
layers = [
imageInputLayer([48510, 1, 1], 'Normalization', 'zscore', 'Name', 'input')
convolution2dLayer(3, 32, 'Padding', 'same')
reluLayer()
maxPooling2dLayer(2, 'Stride', 2)
convolution2dLayer(3, 64, 'Padding', 'same')
reluLayer()
maxPooling2dLayer(2, 'Stride', 2)
fullyConnectedLayer(64)
reluLayer()
fullyConnectedLayer(3)
softmaxLayer()
classificationLayer()
];
% Specify training options
options = trainingOptions('adam', ...
'MaxEpochs', 10, ...
'MiniBatchSize', 10, ...
'ValidationData', {testData, testLabels}, ...
'Plots', 'training-progress');
disp('Size of training data just before training:');
disp(size(trainData));
% Train the network
net = trainNetwork(trainData, trainLabels, layers, options);
% Function to load audio data from a folder
function audioData = loadAudioData(folderPath)
audioFiles = dir(fullfile(folderPath, '*.wav'));
numFiles = numel(audioFiles);
% Initialize audioData as a cell array
audioData = cell(1, numFiles);
for i = 1:numFiles
filePath = fullfile(folderPath, audioFiles(i).name);
disp(['Loading audio file: ', filePath]);
[audio, ~] = audioread(filePath);
% Normalize audio data
audio = audio / max(abs(audio));
% Store audio data in a cell array
audioData{i} = audio;
end
% Find the maximum number of samples among all files
maxSamples = max(cellfun(@numel, audioData));
% Preallocate audioData as a cell array of 2D matrices
audioDataPadded = cell(1, numFiles);
% Populate audioDataPadded with padded/truncated audio data
for i = 1:numFiles
currentAudio = audioData{i};
% Pad or truncate to match the maximum number of samples
currentAudioPadded = padarray(currentAudio, [maxSamples - numel(currentAudio), 0], 0, 'post');
% Assign the padded/truncated audio to audioDataPadded
audioDataPadded{i} = currentAudioPadded;
end
% Convert audioDataPadded to a 4D array
audioDataArray = cat(4, audioDataPadded{:});
% Convert audioDataArray to single precision (if needed)
audioData = single(audioDataArray);
end
solving my problem by removing the error and tuning the code for optimum output