You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux HPC上MATLAB narxnet训练因-nojvm触发UI窗口报错求助

解决Linux HPC无JVM环境下MATLAB NARX网络训练的UI报错问题

问题背景

在Windows桌面可正常运行的MATLAB NARX网络代码,迁移到Linux HPC(CPU环境,启用-nojvm启动选项)训练时,已注释view(net)规避UI操作,但仍触发JVM相关报错,无法完成训练。

报错信息

Error using appwindowfactory
This functionality is not supported under the -nojvm startup option.

Error in matlab.ui.internal.uifigureImpl (line 80)
window = appwindowfactory('WindowStyle','normal',...

Error in uifigure (line 26)
window = matlab.ui.internal.uifigureImpl(varargin{:});

Error in nnet.guis.StandaloneTrainToolView (line 115)
            this.Figure = uifigure('Visible', 'off',...

Error in nnet.guis.NNTrainToolFactory/createStandaloneView (line 12)
            view = nnet.guis.StandaloneTrainToolView(this);

Error in nnet.guis.StandaloneTrainToolPresenter (line 32)
            this.StandaloneTrainToolView = this.TrainToolFactory.createStandaloneView();

Error in nnet.guis.NNTrainToolFactory/createStandalonePresenter (line 8)
            presenter = nnet.guis.StandaloneTrainToolPresenter(this);

Error in nnet.train.TrainToolFeedback/startImpl (line 70)
                    this.TrainToolPresenter = this.TrainToolFactory.createStandalonePresenter();

Error in nnet.train.FeedbackHandler/start (line 18)
        this.startImpl(useSPMD,data,net,tr,options,status);

Error in nnet.train.MultiFeedback/startImpl (line 29)
        this.Handlers{i}.start(useSPMD,data,net,tr,options,status);

Error in nnet.train.FeedbackHandler/start (line 18)
        this.startImpl(useSPMD,data,net,tr,options,status);

Error in nnet.train.trainNetwork>trainNetworkInMainThread (line 42)
feedback.start(false,rawData,archNet,worker.tr,calcLib.options,worker.status);

Error in nnet.train.trainNetwork (line 27)
    [archNet,tr] = trainNetworkInMainThread(archNet,rawData,calcLib,calcNet,tr,feedback,localFcns);

Error in trainscg>train_network (line 145)
[archNet,tr] = nnet.train.trainNetwork(archNet,rawData,calcLib,calcNet,tr,localfunctions);

Error in trainscg (line 55)
            [out1,out2] = train_network(varargin{2:end});

Error in network/train (line 380)
    [net,tr] = feval(trainFcn,'apply',net,data,calcLib,calcNet,tr);

问题代码片段

% Create a NARX network. Define the input delays, feedback delays, and size of the hidden layers.
net = narxnet(1:4,1:4,4);
% Prepare the time series data using preparets. This function automatically shifts input and target time series by the number of steps needed to fill the initial input and layer delay states.
[Xs,Xi,Ai,Ts] = preparets(net,Xcell,{},Ycell);
% Train the NARX network. The train function trains the network in an open loop (series-parallel architecture), % including the validation and testing steps.
net.trainFcn = 'trainscg'  % to avoid the memory issue BackpropJacobi
net = train(net,Xs,Ts,Xi,Ai);
% view(net)

% Calculate the network output Y, final input states Xf, and final layer states Af of the open-loop network from the network input Xs, initial input states Xi, and initial layer states Ai.
[Y,Xf,Af] = net(Xs,Xi,Ai);

解决方案

报错原因是train函数默认会初始化训练工具的UI组件(即使设置为不可见),而-nojvm模式下不支持任何UI相关操作。需要修改网络训练选项,完全禁用训练GUI,改用命令行模式:

在调用train函数前,添加以下代码关闭训练UI:

% 禁用训练GUI,使用命令行输出
net.trainParam.showWindow = false;
net.trainParam.showCommandLine = true;

修改后的完整训练代码片段:

% Create a NARX network. Define the input delays, feedback delays, and size of the hidden layers.
net = narxnet(1:4,1:4,4);
% Prepare the time series data using preparets. This function automatically shifts input and target time series by the number of steps needed to fill the initial input and layer delay states.
[Xs,Xi,Ai,Ts] = preparets(net,Xcell,{},Ycell);
% Train the NARX network. The train function trains the network in an open loop (series-parallel architecture), % including the validation and testing steps.
net.trainFcn = 'trainscg';  % 注意添加分号避免不必要输出
% 禁用训练GUI,适配无JVM环境
net.trainParam.showWindow = false;
net.trainParam.showCommandLine = true;
net = train(net,Xs,Ts,Xi,Ai);
% view(net)

% Calculate the network output Y, final input states Xf, and final layer states Af of the open-loop network from the network input Xs, initial input states Xi, and initial layer states Ai.
[Y,Xf,Af] = net(Xs,Xi,Ai);

额外注意:确保MATLAB启动时确实使用-nojvm选项,同时避免任何其他隐式调用UI的函数(如部分绘图、可视化函数)。

内容的提问来源于stack exchange,提问作者Sanjeet Limbu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 10:10:51