関数endclearに関するエラーの解決法
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
こんにちは。小熊塁です。
分類ネットワークの回帰ネットワークへの変換 というドキュメントを元に
cd 'D:\Thasis\回帰用データセット25転移'
folder_name=pwd;
imds=imageDatastore(folder_name);
XValidation=zeros(227,227,1,25);
for i=1:numel(imds.Files)
I=imread(imds.Files{i});
XValidation(:,:,:,i)=I;
end
YTrain=[216.7;276.7;258.3;126.7;223.3;156.7;215.0;213.3;203.3;258.3;
143.3;180.0;148.3;261.7;163.3;235.0;220;305.0;183.3;146.7;200.0;175.0;123.3;106.7;178.3;206.7;183.3;
145.0;245.0;218.3;220.0;270.0;148.3;163.3;193.3;215.0;141.7;281.7;173.3;156.7;176.7;146.7;205.0;
168.3;195.0;220.0;113.3;131.7;115.0;105.0;108.3;118.3;143.3;118.3;95.0;115.0;123.3;173.3;216.7;113.3;181.7;161.7;135.0;
141.7;123.3;216.7;153.3;233.3;151.7;153.3];
YValidation=[174.2;313.3;286.7;316.7;145.0;193.3;316.7;243.3;228.3;241.7;230.0;115.0;206.7;216.7;138.3;146.7;223.3;275.0;163.3;158.3;128.3;216.7;158.3;138.3;135.0];
net = squeezenet;
layers = net.Layers;
numResponses = 1;
layers = [
layers(1:12)
fullyConnectedLayer(numResponses)
regressionLayer];
layers(1:12) = freezeWeights(layers(1:12));
options = trainingOptions('sgdm',...
'InitialLearnRate',0.001, ...
'ValidationData',{XValidation,YValidation},...
'Plots','training-progress',...
'Verbose',false);
net = trainNetwork(XTrain,YTrain,layers,options);
YPred = predict(net,XValidation);
predictionError = YValidation - YPred;
thr = 10;
numCorrect = sum(abs(predictionError) < thr);
numImagesValidation = numel(YValidation);
accuracy = numCorrect/numImagesValidation
rmse = sqrt(mean(predictionError.^2))
という風なコードを作成したのですが、関数freezeWeightsにおける
function layers = freezeWeights(layers)
for ii = 1:size(layers,1)
props = properties(layers(ii));
for p = 1:numel(props)
propName = props{p};
if ~isempty(regexp(propName, 'LearnRateFactor$', 'once'))
layers(ii).(propName) = 0;
end
end
endclear
end
endclearが認識されず、学習まで行きつけません。
もしこれを解決する方法を知っている方がいれば、ご助言を頂きたいです。
よろしくお願いします。
0 commentaires
Réponse acceptée
Kojiro Saito
le 6 Déc 2021
ドキュメントのコード例を確認しましたが、freezeWeightsの中身はendclearではなく、endだけになっていました。
function layers = freezeWeights(layers)
for ii = 1:size(layers,1)
props = properties(layers(ii));
for p = 1:numel(props)
propName = props{p};
if ~isempty(regexp(propName, 'LearnRateFactor$', 'once'))
layers(ii).(propName) = 0;
end
end
end % ← endのみにする
end
おそらく、ワークスペースを消去するために使ったclearコマンドが、freezeWeights.mのfor文のendの後に追記されてしまったのかと思われます。
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!