Can't use a Validation set when training a sequence-to-sequence BiLSTM Classification model
显示 更早的评论
I am trying to train a sequence-to-sequnce classifcation model, and i use a BiLSTM layer, with Data and labels, X and Y respectively. I am getting the following error:
Error using trainNetwork (line 184)
Training and validation responses must have the same categories. To view the categories of the
responses, use the categories function.
Error in my_DNN_script (line 146)
[net , netInfo] = trainNetwork(X,Y,layers,options);
Caused by:
Error using nnet.internal.cnn.trainNetwork.DLTDataPreprocessor>iAssertClassNamesAreTheSame (line
213)
Training and validation responses must have the same categories. To view the categories of the
responses, use the categories function.
--------------------------------------------------------------------------
I set a breakpoint at the corresponding line in nnet.internal.cnn.trainNetwork.DLTDataPreprocessor>iAssertClassNamesAreTheSame (line 213).
function iAssertClassNamesAreTheSame(trainingCategories, validationCategories)
% iHaveSameClassNames Assert that the class names for the training and
% validation responses are the same.
trainingClassNames = categories(trainingCategories);
validationClassNames = categories(validationCategories);
if ~isequal(trainingClassNames, validationClassNames)
error(message('nnet_cnn:trainNetwork:TrainingAndValidationDifferentClasses'));
end
end
the problem appears to be an ordering problem. I printed the outputs of the variables trainingClassNames and validationClassNames . The number of classes is the same, but the order is different
>> trainingClassNames =
13×1 cell array
{'2' }
{'3' }
{'4' }
{'5' }
{'6' }
{'7' }
{'8' }
{'9' }
{'10'}
{'11'}
{'12'}
{'1' }
{'0' }
>> validationClassNames
validationClassNames =
13×1 cell array
{'0' }
{'1' }
{'3' }
{'4' }
{'5' }
{'6' }
{'7' }
{'8' }
{'9' }
{'10'}
{'11'}
{'12'}
{'2' }
I modifed the function nnet.internal.cnn.trainNetwork.DLTDataPreprocessor>iAssertClassNamesAreTheSame:
I used the function reordercats to do so:
function iAssertClassNamesAreTheSame(trainingCategories, validationCategories)
% iHaveSameClassNames Assert that the class names for the training and
% validation responses are the same.
trainingClassNames = categories(reordercats(trainingCategories));
validationClassNames = categories(reordercats(validationCategories));
if ~isequal(trainingClassNames, validationClassNames)
error(message('nnet_cnn:trainNetwork:TrainingAndValidationDifferentClasses'));
end
end
With this modification, the trainnet function ran without an error.
Could you please tell me if this modification should be flowless, of if it could be leading to a hidden, wrong training behaviour
1 个评论
Steve Philbert
2023-10-12
I am training a classification network with k-fold cross-validation and ran into this same error. When the training and validation categories are reordered, as shown above, their values are equal.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Gaussian Process Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!