Undefined function handle error when loading a neural network that contain a function layer
8 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I created a neural network that uses a functionLayer that I defined by :
functionLayer(@Feature_wise_LM,Name="FiLM_64",Formattable=1,NumInputs=2,NumOutputs=1)
However, when I save the trained neural network with :
save("./trained_networks/FiLM", "trained_network");
and reload it in the same script with :
trained_network = load("./trained_networks/FiLM.mat");
trained_network = trained_network.trained_network;
I get the error :
Warning: While loading an object of class 'dlnetwork':
Error using nnet.internal.cnn.layer.GraphExecutor/propagate (line 354)
Execution failed during layer(s) 'FiLM_64'.
Error in deep.internal.network.ExecutableNetwork/configureForInputsAndForwardOnLayer (line 347)
propagate(this, fcn, Xs, outputLayerIdx, outputLayerPortIdx);
Error in deep.internal.network.EditableNetwork/convertToDlnetwork (line 101)
[executableNetwork, layerOutputSizes] = configureForInputsAndForwardOnLayer(...
Error in dlnetwork.loadobj (line 741)
net = convertToDlnetwork(privateNet, exampleInputs, initializeNetworkWeights);
Caused by:
Undefined function handle.
Error in nnet.cnn.layer.FunctionLayer/predict (line 61)
[varargout{1:layer.NumOutputs}] = layer.PredictFcn(varargin{:});
I tried to save the function in a dedicated file "Feature_wise_LM.m" , but it didn't work
0 件のコメント
回答 (1 件)
Matt J
2025 年 6 月 26 日
編集済み: Matt J
2025 年 6 月 26 日
I tried to save the function in a dedicated file "Feature_wise_LM.m" , but it didn't work
It should work. Make sure the location of that file is on the Matlab path.
Make sure as well that it is in the same location as when the functionLayer was created, though I'm not sure it is absolutely necessary.
6 件のコメント
Matt J
2025 年 6 月 27 日
編集済み: Matt J
2025 年 6 月 27 日
However, in your example the function is in the same script.
The example didn't require that. Here it is again, with testFun defined in its own mfile, as you claim you are doing. It still works, even without wrapping the handle in an anonymous function:
net=dlnetwork(functionLayer(@testFun,Name="FiLM_64",Formattable=1,NumInputs=2,NumOutputs=1), ...
dlarray(1,'SSC'),dlarray(2,'SSC'));
save('netfile.mat', 'net')
clear
load('netfile.mat', 'net')
net,
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!