Which dimension(s) does trainingOptions shuffle apply to?

3 visualizzazioni (ultimi 30 giorni)
Hi all,
How do I know which dimension(s) the trainingOptions shuffle shuffles or how could I figure it out? The wiki does not state it sadly.
My assumption would be for e.g. TxCxB data that is shuffles the batches.
Side question, I would assume that it would keep input-output pairs intact, including for multi-task learning models?
Thanks in advance!
Edit:
I made the following code to try to understand what is going on. If you set a breakpoint at the end of the loss function you can inspect variable b. Assuming that reshape does not alter the data, the first and second dimension of b are not altered compared to A. Therefor, only the batches have been shuffled. However, I do not know and haven't been able to figure out if it always shuffles the batches or that some other thing is playing a part.
close all
clear all
clc
% Generate simple input and output data
A = reshape(1:210, [7,5,6]); % Example input data
% % Convert to table for trainnet compatibility
% trainData = array2table(A, 'VariableNames', {'Input'});
% trainLabels = array2table(A, 'VariableNames', {'Output'});
% Define a simple feedforward network
layers = [
sequenceInputLayer(5)
fullyConnectedLayer(5)
];
% Set training options with shuffle 'every-epoch'
MLoptions = trainingOptions('adam', ...
'MaxEpochs', 5, ...
'Shuffle', 'every-epoch', ...
'Verbose', true,...
'InputDataFormats','TCB');
% Train the network with a custom loss function
net = trainnet(A, A, layers, @customLossFunction, MLoptions);
% ----------------------------
% Inline Custom Loss Function
% ----------------------------
function loss = customLossFunction(Y,T)
% Example custom loss: Mean Squared Error (MSE)
loss = mean((Y - T).^2, 'all');
b=permute(extractdata(T), [3,1,2]);
end
  4 Commenti
Corné Dijkstra
Corné Dijkstra il 20 Mar 2025
I think so far my findings (see edit) are similar to the shuffleing of batches within the mini-batch.
And I asked in the forum here, since an AI would not know the answer if it has not been stated before on the web which it hasn't according to my quick search.
Stephen23
Stephen23 il 20 Mar 2025
"... if it has not been stated before on the web which it hasn't according to my quick search."
Then please do make a documentation enhancement suggestion here:

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 18 Mar 2025
You can use analyzeNetwork to see which dimension is the batch dimension.However, I believe it will always be the last dimension.
  3 Commenti
Matt J
Matt J il 20 Mar 2025
Modificato: Matt J il 20 Mar 2025
It is always the (B) dimension which is shuffled. If your data is TxCxB, the shuffling process is equivalent to doing,
shuffledData = Data(:,:,randperm(end));
Matt J
Matt J il 20 Mar 2025
Modificato: Matt J il 20 Mar 2025
I think so far my findings (see edit) are similar to the shuffleing of batches within the mini-batch.
I don't understand how your are using the terminology "batch" as distinct from "minibatch". The process of shuffling training samples and the process of dividing training samples into minibatches are entirely separate and independent (assuming you are not using a custom datastore). Both processes, however, operate along the (B) dimension of your data.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Data Workflows in Help Center e File Exchange

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by