trainNetwork
)时,我们得到具有线性垂直轴的图表,如下所示:
此图表应提供有关训练进度的一些图形反馈,并且对于分类问题(其中 y 轴代表“准确度 (%)”),它可能会,但在回归问题中,RMSE 值可能会有很大差异。随着训练的进行,数量级会有所不同 - 使得初始下降后的所有内容都难以区分且毫无用处。
我想做的是将垂直轴转换为对数,得到以下结果:
(我不介意一些图形元素在这个过程中移动或丢失,因为曲线对我来说很重要。)
我现在的做法是暂停训练过程,然后手动运行
set(findall(findall(0,'type','figure'),'type','Axes',...
'Tag','NNET_CNN_TRAININGPLOT_AXESVIEW_AXES_REGRESSION_RMSE'),'YScale','log');
(或其某些变体,取决于开放数字等)。
我正在寻找一种无需用户干预即可更改比例的方法,并尽可能在训练开始时进行更改。另外,如果我可以选择重新调整哪个图表(RMSE 和/或损失),那就太好了。
我使用的是R2018a。
生成此类图形所需的最少代码(基于标题为“Train Network for Image Regression”的 MATLAB 文档):
[XTrain,~,YTrain] = digitTrain4DArrayData;
layers = [ ...
imageInputLayer([28 28 1])
convolution2dLayer(12,25)
reluLayer
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.001, ...
'Verbose',false, ...
'MaxEpochs',5, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
'OutputFcn'
机制,并指定一个进行重新缩放的函数。用户可以通过变量 whichAx
来控制重新缩放哪些轴。
function net = q51762507()
[XTrain,~,YTrain] = digitTrain4DArrayData;
layers = [ ...
imageInputLayer([28 28 1])
convolution2dLayer(12,25)
reluLayer
fullyConnectedLayer(1)
regressionLayer];
whichAx = [false, true]; % [bottom, top]
options = trainingOptions('sgdm', ...
'InitialLearnRate',0.001, ...
'Verbose',false, ...
'MaxEpochs',5, ...
'Plots','training-progress',...
'OutputFcn', @(x)makeLogVertAx(x,whichAx) );
net = trainNetwork(XTrain,YTrain,layers,options);
function stop = makeLogVertAx(state, whichAx)
stop = false; % The function has to return a value.
% Only do this once, following the 1st iteration
if state.Iteration == 1
% Get handles to "Training Progress" figures:
hF = findall(0,'type','figure','Tag','NNET_CNN_TRAININGPLOT_FIGURE');
% Assume the latest figure (first result) is the one we want, and get its axes:
hAx = findall(hF(1),'type','Axes');
% Remove all irrelevant entries (identified by having an empty "Tag", R2018a)
hAx = hAx(~cellfun(@isempty,{hAx.Tag}));
set(hAx(whichAx),'YScale','log');
end
这个问题已经讨论很久了,但是对于较新版本的 MATLAB,输出函数需要稍作更改。感谢@Dev-iL 提供原始解决方案。
function stop = makeLogVertAx(state, whichAx)
stop = false; % The function has to return a value.
% Only do this once, following the 1st iteration
if state.Iteration == 1
% Get handles to "Training Progress" figures:
hF = findall(0,'type','figure','Tag','NNET_CNN_TRAININGPLOT_UIFIGURE');
% Assume the latest figure (first result) is the one we want, and get its axes:
hAx = findall(hF(1),'type','Axes');
% Remove all irrelevant entries (identified by having an empty "Tag", R2018a)
hAx = hAx(cellfun(@(x)contains(x,"AXESVIEW"),{hAx.Tag})); % hAx(~cellfun(@isempty,{hAx.Tag}));
set(hAx(whichAx),'YScale','log');
end
对新答案表示歉意,但还无法回复原来的答案。