Matlab - 如何保存matlab神经网络的视图配置

问题描述 投票:0回答:4

我正在尝试使用 matlab 和

newff
命令配置神经网络。

之后,我尝试使用

view
命令可视化我创建的配置。

x = view(net);

如何将显示的窗口保存到

.png
文件中?我已经尝试过
saveas(x, 'figure.png', 'png')
但它不起作用?你知道我如何通过代码做到这一点吗?

neural-network matlab matlab-figure
4个回答
8
投票

创建的窗口是一个纯Java图形(不是MATLAB Handle Graphics)。试试这个来捕捉它:

%# neural net, and view it
net = feedforwardnet(5);
jframe = view(net);

%# create it in a MATLAB figure
hFig = figure('Menubar','none', 'Position',[100 100 565 166]);
jpanel = get(jframe,'ContentPane');
[~,h] = javacomponent(jpanel);
set(h, 'units','normalized', 'position',[0 0 1 1])

%# close java window
jframe.setVisible(false);
jframe.dispose();

%# print to file
set(hFig, 'PaperPositionMode', 'auto')
saveas(hFig, 'out.png')

%# close figure
close(hFig)

0
投票

我也有同样的问题,特别是当我尝试保存神经网络工具箱(nntraintool)生成的图时。我使用截图工具来捕捉这些图。不过,请尝试使用以下一个:

识别您需要快照的 gfx 对象(其手柄)。它将来自可识别的属性。然后您可以使用打印选项将其保存到文件中;你需要写下文件名、类型;请访问此链接了解更多信息 (http://www.mathworks.com/help/matlab/ref/print.html)。

例如,如果您想保存带有标签“performance.fig”的图形,您可以尝试:

h = findobj('Type', 'figure', 'tag', 'performance.fig');

    for k = 1:numel(h)

    print(h(k), sprintf('Pic%d.ps',k));

    end;

让我知道这是否有帮助,您必须根据需要修改代码。我还从这个 stackoverflow 论坛中的另一个人那里得到了帮助。


0
投票

我试图获取 nntraintool 框的结果并创建网络配置图、生成的训练快照以及性能、训练状态和回归图。

看到建议后,7。我设计了下面的代码来解决这些问题。我会对我的程序风格表示歉意,并希望为这些问题的解决做出贡献。

%***************************************************************************
% TrainingToolDisplays
%***************************************************************************

function [] = TrainingToolDisplays(net,P,T) 

%***************************************************************************
% After configuring the net, do a silent net training
%***************************************************************************

net.trainParam.showWindow = 0;
net = train(net,P,T);

%***************************************************************************
% Create a figure for the net configuration
%***************************************************************************

jConfig = view(net);
hConfig = figure('Name','Neural Network Configuration', ...
                 'NumberTitle','off', ...  
                 'Menubar','none', ...
                 'Position',[100 100 600 200], ...
                 'PaperPositionMode', 'auto', ...
                 'Visible','on');

jPanel = get(jConfig,'ContentPane');
[~,h] = javacomponent(jPanel);
set(h, 'units','normalized', 'position',[0 0 1 1])
jConfig.setVisible(false)
jConfig.dispose

%***************************************************************************
% Create a figure for the nntraintool training snap shot
%***************************************************************************

jTrainTool = nntraintool('handle');
hTrainTool = figure('Name','Neural Network Training', ...    
                    'NumberTitle','off', ...  
                    'Menubar','none', ...
                    'Position',[100 100 600 600], ...
                    'PaperPositionMode', 'auto', ...
                    'Visible','on');

jPanel = get(jTrainTool,'ContentPane');
[~,h] = javacomponent(jPanel);
set(h, 'units','normalized', 'position',[0 0 1 1])
jTrainTool.setVisible(false)
jTrainTool.dispose

%***************************************************************************
% Plot the plots you want and get the handles 
%***************************************************************************

nntraintool('plot', 'plotperform');    hPerform = gcf;
nntraintool('plot', 'plottrainstate'); hTrainState = gcf;
nntraintool('plot', 'plotregression'); hRegression = gcf;

%***************************************************************************
% Now you may do whatever you may want with those matlab handles
% hConfig, hTrainTool, hPerform, hTrainState and bRegression
%***************************************************************************

return
%*******************************************************************************

0
投票

至少在 R220b 中这是有效的:

% Create and configure network
net = timedelaynet([1:8], 10);
net= configure(net, {1}, {1});

% This is internally called by view(net) and returns a java object
hv= nnet.internal.nnviz.StandaloneDiagramWidget(net);
% ... that can be used to interact with the graphic
hv.waitUntilDiagramRendered
% ... and get its image data
img= hv.getImageDataForSnapshot;
hv.delete

imwrite(img, 'ftdnn.png')
© www.soinside.com 2019 - 2024. All rights reserved.