【问题标题】:Matlab - How to save view configuration of matlab neural networkMatlab - 如何保存matlab神经网络的视图配置
【发布时间】:2013-02-01 20:53:42
【问题描述】:

我正在尝试使用 matlab 和 newff 命令配置神经网络。

之后,我尝试使用view 命令可视化我创建的配置。

x = view(net);

如何将显示的窗口保存到.png 文件?我试过saveas(x, 'figure.png', 'png'),但它不起作用?你知道我如何通过代码做到这一点吗?

【问题讨论】:

    标签: neural-network matlab matlab-figure


    【解决方案1】:

    创建的窗口是一个纯 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)
    

    【讨论】:

      【解决方案2】:

      我也有同样的问题,特别是当我尝试保存神经网络工具箱 (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 论坛上从另一个人那里得到了帮助。

      【讨论】:

      • 这不起作用(findobjallchild(0) 都不会找到有问题的窗口)
      【解决方案3】:

      我试图获取 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
      %*******************************************************************************
      

      【讨论】:

        猜你喜欢
        • 2015-12-03
        • 2011-08-23
        • 2010-11-20
        • 2011-07-31
        • 2014-04-09
        • 2015-07-21
        • 2011-06-02
        • 2012-09-19
        • 1970-01-01
        相关资源
        最近更新 更多