Error for dlarray format, but why?
5 次查看(过去 30 天)
显示 更早的评论
K>> lstm(dlX, hiddenState, initialCellState, inputWeights, ...
recurrentWeights, bias)
Error using deep.internal.dlarray.validateWeights (line 9)
'U' dimension (if not a formatted dlarray, second dimension) of weights must have size
NumFeatures, where NumFeatures is the size of the 'C' dimension of the input data.
Can any expert help me to solve this issue? Also I am still quite confused about the concept with the format labels C S T U B
Is there any simple explanation for tutorial for their usage?
Many thks
1 个评论
回答(1 个)
Ben
2023-6-20
This error appears to be thrown if the inputWeights have the wrong size, e.g. you can take this example code from help lstm
numFeatures = 10;
numObservations = 32;
sequenceLength = 64;
X = dlarray(randn(numFeatures,numObservations,sequenceLength), 'CBT');
% Create formatted dlarrays for the lstm parameters with three
% hidden units.
numHiddenUnits = 3;
H0 = dlarray(randn(numHiddenUnits,numObservations),'CB');
C0 = dlarray(randn(numHiddenUnits,numObservations),'CB');
weights = dlarray(randn(4*numHiddenUnits,numFeatures),'CU');
recurrent = dlarray(randn(4*numHiddenUnits,numHiddenUnits),'CU');
bias = dlarray(randn(4*numHiddenUnits,1),'C');
% Apply an lstm calculation
[Y,hiddenState,cellState] = lstm(X,H0,C0,weights,recurrent,bias);
If you now make weights the wrong size in the 2nd dimension you get the error:
errorWeights = dlarray(randn(4*numHiddenUnits,numFeatures+1),'CU');
lstm(X,H0,C0,errorWeights,recurrent,bias); % throws error
This suggests your inputWeights have the wrong size to use lstm. The inputWeights require a size of 4*NumHiddenUnits x NumFeatures, and they can either be a dlarray with format labels or without:
% both of these are valid - the format label U is just to specify that this
% dimension doesn't correspond to any of the standard named labels S -
% spatial, C - channel, T - time, B - batch.
weights = dlarray(randn(4*numHiddenUnits,numFeatures),'CU');
weights = dlarray(randn(4*numHiddenUnits,numFeatures));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!