Using CTC los function with trainnet
Hi! I am designing a neural network to do phoneme classifcation for a simple speech recogniser. I’ve been evaluating the idea of using Connectionist Temporal Classifcation (CTC) as the loss function for this task, as other loss functions haven’t shown good results. Both my training and validation data are structured as an array datastore containing MFCC matrixs and the corresponding phoneme label to each matrix.
I’ve first tried by using a custom loop as the Matlab page suggests for this task, but I’ve had many problems developing the code, so now I’ve been trying to implement the CTC loss function into ‘trainnet’ this way:
numClasses = numel(unique(letras));
% Definir la arquitectura de la red neuronal
layers = [
sequenceInputLayer(39, "Normalization","zscore")
convolution1dLayer(15,20,’Padding’, ‘same’)
tanhLayer
convolution1dLayer(10,20,’Padding’,’same’)
tanhLayer
dropoutLayer(0.4)
convolution1dLayer(5,20,’Padding’,’same’)
tanhLayer
globalAveragePooling1dLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
% Definir opciones de entrenamiento
options = trainingOptions(‘adam’, …
‘MaxEpochs’,50, …
‘MiniBatchSize’,64, …
‘ValidationData’, mfcc_dts_validate, …
‘Plots’,’training-progress’,…
‘Metrics’, ‘accuracy’);
% Entrenar la red neuronal
[net, info] = trainnet(mfcc_dts_train, layers, @modelLoss, options);
Where the model loss function is written as if it was meant to be used with a custom loop:
function [loss,gradients,state] = modelLoss(net,X,T)
Y = predict(net, X);
loss = ctc(Y,T);
% Calculate gradients of loss with respect to learnable parameters.
gradients = dlgradient(loss,net.Learnables);
end
The error I obtain is:
Error using trainnet
Caused by:
Undefined function ‘predict’ for input arguments of type ‘dlarray’.
I’m not quite sure of how to use a custom loss function into trainnet properly, as I don’t understand how to use the different inputs and outputs during training as the input data for the custom loss function. I’ve tried following the different tutorials for custom loops and loss functions, but I haven’t seen an example code for this case. If someone has an idea of how to face this, let me know!Hi! I am designing a neural network to do phoneme classifcation for a simple speech recogniser. I’ve been evaluating the idea of using Connectionist Temporal Classifcation (CTC) as the loss function for this task, as other loss functions haven’t shown good results. Both my training and validation data are structured as an array datastore containing MFCC matrixs and the corresponding phoneme label to each matrix.
I’ve first tried by using a custom loop as the Matlab page suggests for this task, but I’ve had many problems developing the code, so now I’ve been trying to implement the CTC loss function into ‘trainnet’ this way:
numClasses = numel(unique(letras));
% Definir la arquitectura de la red neuronal
layers = [
sequenceInputLayer(39, "Normalization","zscore")
convolution1dLayer(15,20,’Padding’, ‘same’)
tanhLayer
convolution1dLayer(10,20,’Padding’,’same’)
tanhLayer
dropoutLayer(0.4)
convolution1dLayer(5,20,’Padding’,’same’)
tanhLayer
globalAveragePooling1dLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
% Definir opciones de entrenamiento
options = trainingOptions(‘adam’, …
‘MaxEpochs’,50, …
‘MiniBatchSize’,64, …
‘ValidationData’, mfcc_dts_validate, …
‘Plots’,’training-progress’,…
‘Metrics’, ‘accuracy’);
% Entrenar la red neuronal
[net, info] = trainnet(mfcc_dts_train, layers, @modelLoss, options);
Where the model loss function is written as if it was meant to be used with a custom loop:
function [loss,gradients,state] = modelLoss(net,X,T)
Y = predict(net, X);
loss = ctc(Y,T);
% Calculate gradients of loss with respect to learnable parameters.
gradients = dlgradient(loss,net.Learnables);
end
The error I obtain is:
Error using trainnet
Caused by:
Undefined function ‘predict’ for input arguments of type ‘dlarray’.
I’m not quite sure of how to use a custom loss function into trainnet properly, as I don’t understand how to use the different inputs and outputs during training as the input data for the custom loss function. I’ve tried following the different tutorials for custom loops and loss functions, but I haven’t seen an example code for this case. If someone has an idea of how to face this, let me know! Hi! I am designing a neural network to do phoneme classifcation for a simple speech recogniser. I’ve been evaluating the idea of using Connectionist Temporal Classifcation (CTC) as the loss function for this task, as other loss functions haven’t shown good results. Both my training and validation data are structured as an array datastore containing MFCC matrixs and the corresponding phoneme label to each matrix.
I’ve first tried by using a custom loop as the Matlab page suggests for this task, but I’ve had many problems developing the code, so now I’ve been trying to implement the CTC loss function into ‘trainnet’ this way:
numClasses = numel(unique(letras));
% Definir la arquitectura de la red neuronal
layers = [
sequenceInputLayer(39, "Normalization","zscore")
convolution1dLayer(15,20,’Padding’, ‘same’)
tanhLayer
convolution1dLayer(10,20,’Padding’,’same’)
tanhLayer
dropoutLayer(0.4)
convolution1dLayer(5,20,’Padding’,’same’)
tanhLayer
globalAveragePooling1dLayer
fullyConnectedLayer(numClasses)
softmaxLayer];
% Definir opciones de entrenamiento
options = trainingOptions(‘adam’, …
‘MaxEpochs’,50, …
‘MiniBatchSize’,64, …
‘ValidationData’, mfcc_dts_validate, …
‘Plots’,’training-progress’,…
‘Metrics’, ‘accuracy’);
% Entrenar la red neuronal
[net, info] = trainnet(mfcc_dts_train, layers, @modelLoss, options);
Where the model loss function is written as if it was meant to be used with a custom loop:
function [loss,gradients,state] = modelLoss(net,X,T)
Y = predict(net, X);
loss = ctc(Y,T);
% Calculate gradients of loss with respect to learnable parameters.
gradients = dlgradient(loss,net.Learnables);
end
The error I obtain is:
Error using trainnet
Caused by:
Undefined function ‘predict’ for input arguments of type ‘dlarray’.
I’m not quite sure of how to use a custom loss function into trainnet properly, as I don’t understand how to use the different inputs and outputs during training as the input data for the custom loss function. I’ve tried following the different tutorials for custom loops and loss functions, but I haven’t seen an example code for this case. If someone has an idea of how to face this, let me know! neural network, custom loss function, ctc, trainnet MATLAB Answers — New Questions