針金の共進周波数の読み取り
1 view (last 30 days)
Show older comments
針金を何段階かに分けて振動させています。その針金の共進周波数をディープラーニングで読み取るためのプログラムを作りました。
しかしエラーが出てしまい対策が分かりません教えてください。
% 動画ファイルのパスを格納
videoFiles = {'gazuosyori10.MOV', 'gazousyori20.MOV', 'gazousyori30.MOV', 'gazousyori40.MOV', 'gazousyori50.MOV', 'gazousyori60.MOV', 'gazousyori70.MOV', 'gazousyori80.MOV', 'gazousyori90.MOV', 'gazousyori100.MOV'};
% 動画ファイルの数を取得
numFiles = length(videoFiles);
% 特徴量とラベルの初期化
featureSize = 10; % 特徴量の次元数を10に設定
numFramesPerVideo = 10; % 動画あたりのフレーム数
features = zeros(numFramesPerVideo, featureSize, numFiles); % 配列の初期化
labels = zeros(numFiles, 1);
for i = 1:numFiles
v = VideoReader(videoFiles{i});
for j = 1:numFramesPerVideo
if hasFrame(v)
frame = readFrame(v);
features(j, :, i) = extractFeature(frame);
else
break; % フレームがない場合はループを抜ける
end
end
labels(i) = i;
end
% データの正規化
features = normalize(features, 'range');
% ラベルのカテゴリ化
labels = categorical(labels);
% 特徴量配列の形状を変更
featuresReshaped = reshape(features, [numFramesPerVideo, featureSize, numFiles]);
% ネットワークアーキテクチャの定義
layers = [
sequenceInputLayer(featureSize)
lstmLayer(50, 'OutputMode', 'last')
fullyConnectedLayer(10) % 出力層のノード数はラベルの数に応じて調整
softmaxLayer
classificationLayer
];
% トレーニングオプションの設定
options = trainingOptions('adam', ...
'MaxEpochs', 100, ...
'MiniBatchSize', 32, ...
'InitialLearnRate', 0.01, ...
'GradientThreshold', 1, ...
'Shuffle', 'every-epoch', ...
'Verbose', false, ...
'Plots', 'training-progress');
featuresReshaped = reshape(features, [featureSize, numFramesPerVideo, numFiles]);
% モデルのトレーニング
net = trainNetwork(featuresReshaped, labels, layers, options);
% ローカル関数
function feature = extractFeature(frame)
% 画像の画素値の平均を特徴量として使用
feature = mean(frame(:));
end
エラー内容が
次を使用中: trainNetwork
トレーニング シーケンスの特徴次元は 10 10 ですが、入力
層には特徴次元 10 のシーケンスが必要です。
エラー: ziken32 (行 55)
net = trainNetwork(featuresReshaped, labels, layers, options);
です
0 Comments
Answers (1)
Varun
on 30 Jan 2024
Hello! I translated the error you encountered to English and it says:
The error occurred while using: trainNetwork
The feature dimension of the training sequence is 10 by 10, but the input layer requires a sequence with a feature dimension of 10.
Error in ziken32 (line 55)
net = trainNetwork(featuresReshaped, labels, layers, options);
I looked at the code snippets you provided and I think the reason this error has come is because the variable "featuresReshaped" is of dimensions 10x10. However, in the variable "layers" which defines the layers of the neural network, we see that the first layer expects an input of the size "featureSize". In the code snippet, the value of "featureSize" is 10.
So, checking and revising the dimensions of the "featuresReshaped" variable and ensuring that it matches the expected input shape for the network's input layer should resolve this error.
Hope this helps!
0 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!