- T: Training target variable of size 860x1 cell, where each cell contains a sequence of 500 labels.
- Y: Predicted values variable, which we assume has the same dimensions as T.
How do I create the loss function of a weighted classification layer with R2020b?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I tried to create a weighted entropy loss function by following the link below step by step:
However, I get the error "Incorrect dimensions for matrix multiplication" when calculating the loss variable, when I multiply the "T" and "Y" variables corresponding to the training target and predicted values respectively. I can't correct my error because I don't know the exact format of the 'softmax layer' in my case.
I'm in the case of a time-step sequence-to-sequence classification problem. This means that the prediction of a label corresponds to a time step. My training target variable is of the form 860*1 cell, with each cell in each row containing a sequence of 500 labels.
Could you please help me to build the forwardLoss correctly so that I don't get this error again?
Thank you for your help,
Kind regards,
0 commentaires
Réponses (1)
Shree Harsha Kodi
le 30 Juin 2023
On defining the dimensions of your variables based on the information you provided:
You can modify the code provided in the MATLAB documentation to handle your case
On iterating over the time steps and convert the cell arrays T and Y into matrices for each time step using the cell2mat function. Then, compute the softmax of Ymat using the softmax function. Finally, calculate the cross-entropy loss for each time step and average it over all time steps.
Make sure to replace WeightedEntropyLossLayer with the appropriate name for your layer, and modify any additional properties or methods as needed.
This should help you build the forwardLoss function correctly for your time-step sequence-to-sequence classification problem.
Go through the following documentations for a better understanding:
1)https://in.mathworks.com/help/deeplearning/ug/create-custom-classification-layer.html
2)https://in.mathworks.com/help/deeplearning/ug/create-custom-classification-layer.html
3)https://in.mathworks.com/help/deeplearning/index.html
0 commentaires
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!