필터 지우기
필터 지우기

How do I create the loss function of a weighted classification layer with R2020b?

조회 수: 5 (최근 30일)
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,

답변 (1개)

Shree Harsha Kodi
Shree Harsha Kodi 2023년 6월 30일
On defining the dimensions of your variables based on the information you provided:
  • 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.
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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by