関数endclearに関するエラーの解決法

조회 수: 1 (최근 30일)
塁 小熊
塁 小熊 2021년 12월 6일
댓글: 塁 小熊 2021년 12월 7일
こんにちは。小熊塁です。
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が認識されず、学習まで行きつけません。
もしこれを解決する方法を知っている方がいれば、ご助言を頂きたいです。
よろしくお願いします。

채택된 답변

Kojiro Saito
Kojiro Saito 2021년 12월 6일
ドキュメントのコード例を確認しましたが、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の後に追記されてしまったのかと思われます。
  댓글 수: 1
塁 小熊
塁 小熊 2021년 12월 7일
なるほど、そういうことでしたか…。
clearを消して保存したところ、無事に動作しました!
ありがとうございます。

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!