Error using trainNetwork (line 191) Invalid network.
21 ビュー (過去 30 日間)
古いコメントを表示
I receive the following error for my function given below. .Would you please help me to correct the function?
for the following input
YPred = trainAndPredictHADEL(XTrain, YTrain, XTest);
++
% Function to train and predict using HADEL model
function YPred = trainAndPredictHADEL(XTrain, YTrain, XTest)
% Define HADEL model architecture
numFeatures = size(XTrain, 2);
numClasses = numel(categories(YTrain));
% Feature-Level Attention
featureAttention = [
fullyConnectedLayer(64, 'Name', 'fc_feature_attention')
reluLayer('Name', 'relu_feature_attention')
fullyConnectedLayer(1, 'Name', 'fc_feature_weights')
softmaxLayer('Name', 'feature_attention_weights')
];
% Temporal Attention (not used for Iris dataset, but included for completeness)
temporalAttention = [
sequenceInputLayer(numFeatures, 'Name', 'input_sequence')
lstmLayer(64, 'OutputMode', 'sequence', 'Name', 'lstm_temporal_attention')
fullyConnectedLayer(1, 'Name', 'fc_temporal_weights')
softmaxLayer('Name', 'temporal_attention_weights')
];
% Combine into Hierarchical Attention
%%Bu kısmı hata verdi aşağıdaki gibi koydum
% hierarchicalAttention = [
% featureAttention
% temporalAttention
% dotProductLayer(1, 'Name', 'weighted_output')
% ];
hierarchicalAttention = [
featureAttention
temporalAttention
];
% Add classification layers
layers = [
hierarchicalAttention
fullyConnectedLayer(64, 'Name', 'fc_final')
reluLayer('Name', 'relu_final')
fullyConnectedLayer(numClasses, 'Name', 'fc_output')
softmaxLayer('Name', 'softmax_output')
classificationLayer('Name', 'output')
];
% Train the network
options = trainingOptions('adam', ...
'MaxEpochs', 50, ...
'MiniBatchSize', 8, ...
'Verbose', false);
net = trainNetwork(XTrain, YTrain, layers, options);
% Predict on test data
YPred = classify(net, XTest);
end
++
Error
++
Error using trainNetwork (line 191)
Invalid network.
Error in trainAndPredictHADEL (line 54)
net = trainNetwork(XTrain, YTrain, layers, options);
Caused by:
Layer 'fc_feature_attention': Unconnected input. Each layer input must be connected to the output of another layer.
Layer 'input_sequence': An input layer must be first in the layer array.
++
0 件のコメント
採用された回答
Cris LaPierre
2025 年 2 月 2 日 17:36
You are missing an input layer for your model. See the final error message: " Layer 'input_sequence': An input layer must be first in the layer array."
Your first layer is fullyConnectedLayer(64, 'Name', 'fc_feature_attention')
3 件のコメント
Cris LaPierre
2025 年 2 月 3 日 3:07
I think the issue here is that you have defined the concatenation layer to have 2 inputs, but have only provided one. See the concatenationLayer doc page.
Perhaps this layer is not doing what you think. Try removing it.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!