CNNでのTrain​ingOptionで​の学習状況の表示のさ​せ方

R2017bを使用して分類学習を行っているのですが,学習オプションの'plot'を利用して,学習状況の表示をさせています. この時に表示されるグラフの'Smoothed'を非表示にしたいのですが,何か方法や設定ができるのでしょうか. また,この時に表示される軸の文字の大きさについても変更できますか?
宜しくお願いします.

 Respuesta aceptada

michio
michio el 7 de Dic. de 2017
Editada: michio el 7 de Dic. de 2017

0 votos

残念ながら、R2017bでは'Smoothed'を非表示にしたりフォントを変更するなどの変更を加えることはできません。 もし差し支えなければ、'Smoothed' を非表示にされたい理由や、他にもここは変更できるようになった方がよいなどもございましたら教えて頂けませんでしょうか?開発サイドへ要望としてフィードバックいたします。
学習状況を表示する方法として、学習オプションの 'OutputFcn' に表示用の関数を設定する方法があります。これは独自に表示させるプログラムを書く必要があります(それなりに手間です)が、表示内容は自由に設定することができます。ここに設定した関数は学習前、学習後、そして各反復後に実行されます。

11 comentarios

KENji
KENji el 7 de Dic. de 2017
回答ありがとうございます.
やはり,2017a同様に'OutputFcn'を使用しなければならないのですね. 要望等はないのですが,以下のようなコードを書いてみたのですが,Validationの誤差と精度についてプロットしてもらうには,どうすればよいでしょうか?
function plotTrainAc(info)
persistent plot0bj
if info.State=="start"
plot0bj=animatedline('LineStyle','--');
xlabel("Iteration")
ylabel("Epoch")
elseif info.State=="iteration"
addpoints(plot0bj,info.Epoch,info.ValidationLoss)
drawnow limitrate nocallbacks
end
end
appointsの部分でエラーが出ているようなのですが,よくわかりません 宜しくお願いします.
michio
michio el 7 de Dic. de 2017
エラーの内容がわかると嬉しいですが、、Figureのハンドルを persistent変数に加えるとどうなりますか?
function plotTrainAc(info)
persistent plot0bj hfigure
if info.State=="start"
hfigure = figure;
plot0bj=animatedline('LineStyle','--');
xlabel("Iteration")
ylabel("Epoch")
elseif info.State=="iteration"
figure(hfigure)
addpoints(plot0bj,info.Epoch,info.ValidationLoss)
drawnow limitrate nocallbacks
end
end
KENji
KENji el 7 de Dic. de 2017
エラーなのですが,
原因:
エラー: matlab.graphics.animation.AnimatedLine/addpoints
引数 Y はベクトルでなければなりません。
エラー: LastEnpe>plotTrainAc (line 46)
addpoints(plot0bj,info.Epoch,info.ValidationLoss)
というようなエラーが出ています. 教えいていただいた,コードでは学習は行われているようですが,プロット画面の起動がされませんでした.
michio
michio el 8 de Dic. de 2017
addpoints を呼び出している行にブレイクポイントを設定すれば、直接原因を確認できるかと想いますが、おそらく info.ValidationLoss が空なのではと推測しています。trainingOptions で 'ValidationData' は設定されていますか?
KENji
KENji el 8 de Dic. de 2017
何度も,回答いただきありがとうございます. validationDataは,imagedatastoreを使って設定しています. また,一度はValidationLossが計算され,Figureウィンドウが起動するのですが,その後の計算でエラーが出てしまいます. ループでの計算の設定がうまくいっていないのでしょうか?
optionsA=trainingOptions('sgdm',...
'InitialLearnRate',0.0001,...
'MaxEpochs',100',...
'ValidationData',testPerfData,....
'OutputFcn',@(info)plotTrainAc(info));
michio
michio el 8 de Dic. de 2017
こちらでも頂いた plotTrainAc.m を使ってR2017bで実行していますがエラーなく表示されます。
https://jp.mathworks.com/help/nnet/ref/trainnetwork.html にあるサンプルコードからの抜粋です。そのままコピペして実行できるはずですので、試しに実行して頂けますか?
% Load the data as an |ImageDatastore| object.
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet','nndemos',...
'nndatasets','DigitDataset');
digitData = imageDatastore(digitDatasetPath,...
'IncludeSubfolders',true,'LabelSource','foldernames');
% Divide the data set so that each category in the training set has 750 images
% and the testing set has the remaining images from each label.
trainingNumFiles = 10;
rng(1) % For reproducibility
[trainDigitData,testDigitData] = splitEachLabel(digitData,...
trainingNumFiles,'randomize');
Define the convolutional neural network architecture.
layers = [imageInputLayer([28 28 1]);
convolution2dLayer(5,20);
reluLayer();
maxPooling2dLayer(2,'Stride',2);
fullyConnectedLayer(10);
softmaxLayer();
classificationLayer()];
Set the options to default settings for the stochastic gradient descent with momentum. Set the maximum number of epochs at 20, and start the training with an initial learning rate of 0.001.
options = trainingOptions('sgdm','MaxEpochs',20,...
'InitialLearnRate',0.0001,...
'OutputFcn',@plotTrainAc,'ValidationData',trainDigitData);
Train the network.
convnet = trainNetwork(trainDigitData,layers,options);
KENji
KENji el 8 de Dic. de 2017
何度もすみません. 念のため,再インストールして実行してみたのですが,やはり'addpoints'の関数でYに'ValidationLoss'を入れるとエラーが出てしまいます.(TrainingLossの場合はうまくいきました.)
michio
michio el 8 de Dic. de 2017
確認ですが、私が上のコメントで提示したプログラムのコピペ実行でもエラーが発生するということでしょうか?
KENji
KENji el 8 de Dic. de 2017
いえ,ご提示いただいたプログラムではうまくいきました. ただ,関数定義内の
addpoints(plot0bj,info.Epoch,info.TrainingLoss)
のTrainingLossをValidationLossに変えるとエラーが出ている状況です. すみませんが,よろしくお願いします.
michio
michio el 9 de Dic. de 2017
TrainingLoss にしていましたか、失礼いたしました。
今回のエラーは ValidationLoss が iteration 毎に計算されないことが要因の様デスので、
if ~isempty(info.ValidationLoss)
addpoints(plot0bj,info.Epoch,info.ValidationLoss)
drawnow limitrate nocallbacks
end
という条件式を入れる必要がありそうです。学習オプションの 'ValidationFrequency' で Validation の頻度を指定することが出来ますので、ここを1にすれば上の条件式は必要ありませんが、毎回 Validation を行うのも学習効率を考えると大変かと思います。
下記は修正を加えた plotTrainAc です。
function plotTrainAc(info)
persistent plot0bj hfigure
if info.State=="start"
hfigure = figure;
plot0bj=animatedline('LineStyle','--');
xlabel("Iteration")
ylabel("ValidationLoss")
elseif info.State=="iteration"
figure(hfigure)
if ~isempty(info.ValidationLoss)
addpoints(plot0bj,info.Iteration,info.ValidationLoss)
drawnow limitrate nocallbacks
end
end
end
KENji
KENji el 10 de Dic. de 2017
懇切丁寧に教えていただきありがとうございます. うまくいきました. 検証頻度を1にしないと,空の配列を参照してエラーが出ていたんですね.
ありがとうございました.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Dic. de 2017

Comentada:

el 10 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!