Deep Learning Train Bayesian Neural Network

14 ビュー (過去 30 日間)
Joy Wang
Joy Wang 2024 年 3 月 12 日
回答済み: Yash 2024 年 3 月 18 日
when I use the MATLAB TrainBayesianNeuralNetworkUsingBayesByBackpropExample
I can work with good results as it was offered
However, when I copied this code to m.file , named demo_BNN
I have found lots of problems
in Train model section
mbq = minibatchqueue(dsTrain, ...
MiniBatchSize= miniBatchSize, ...
MiniBatchFcn= @preprocessMiniBatch, ...
MiniBatchFormat=["SSCB" "CB"]);
Error using minibatchqueue>iValidateMiniBatchFcn
Invalid value for 'MiniBatchFcn'. Unable to find function 'preprocessMiniBatch'.
Error in minibatchqueue>iParseInputs (line 786)
iValidateMiniBatchFcn(options.MiniBatchFcn, numVariables, options.NumOutputs);
Error in minibatchqueue (line 288)
options = iParseInputs(numVariables, varargin{:});
Error in demo_BNN (line 82)
mbq = minibatchqueue(dsTrain, ...
However, there are similar operations from document of minibatchqueue
SImilaraly, In monitor section
[elboLoss,rmsError,gradientsNet,gradientsNoise] = dlfeval(@modelLoss, ...
net,X,T,samplingNoise,miniBatchIdx,numIterationsPerEpoch);
Undefined function 'modelLoss' for input arguments of type 'dlnetwork'.
Error in deep.internal.dlfeval (line 17)
[varargout{1:nargout}] = fun(x{:});
Error in deep.internal.dlfevalWithNestingCheck (line 19)
[varargout{1:nargout}] = deep.internal.dlfeval(fun,varargin{:});
Error in dlfeval (line 31)
[varargout{1:nargout}] = deep.internal.dlfevalWithNestingCheck(fun,varargin{:});
Error in demo_BNN (line 123)
[elboLoss,rmsError,gradientsNet,gradientsNoise] = dlfeval(@modelLoss, ...

回答 (1 件)

Yash
Yash 2024 年 3 月 18 日
Hi Joy,
I tried reproducing the errors on my end. However, "demo_BNN.mlx" is working fine for me. I created a copy of "TrainBayesianNeuralNetworkUsingBayesByBackpropExample.mlx" and renamed it to "demo_BNN.mlx".
Ensure the following to try to resolve the errors:
  • Check that all the supporting functions ("preprocessMiniBatch", "modelPosteriorSample", "logLikelihood", "modelLoss", "negativeELBO", "averageNegativeELBO" and "KLWeight") are defined at the end of "demo_BNN.mlx". These functions are defined in "TrainBayesianNeuralNetworkUsingBayesByBackpropExample.mlx".
  • Check that all the helper .M files are present in the same directory as "demo_BNN.mlx". These files are "bayesFullyConnectedLayer.m", "initializeGlorot.m" and "logProbabilityNormal.m". These files are present in the same directory as "TrainBayesianNeuralNetworkUsingBayesByBackpropExample.mlx".
Attaching "demo_BNN.mlx" and other helper functions for your reference.

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by