Initialize a Neural Network from layers but do NOT train

· May 12, 2021 · 2K views
Question
I want to initialize a neural network from a set of layers, but I do not want to train it. Basically I just want to create it as a forward model, set the weights and biases randomly, and be able to evaluate it at given data point. The tutorials and documentation are not very clear on how to do this. For example from https://www.mathworks.com/help/nnet/examples/create-simple-deep-learning-network-for-classification.html they have       layers = [imageInputLayer([28 28 1]) convolution2dLayer(5,20) reluLayer maxPooling2dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer()]; But then they define the network through a training function: convnet = trainNetwork(trainDigitData,layers,options); I don't want this. I just want something along the lines of convnet = network(layers); Then I want to be able manually access all weights and biases, set them as I wish and be able to evaluate the network at a single or multiple input images. Is this possible? Thank you.
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 20, 2026
Since
 
 

 

 trainedNet = trainNetwork(X, Y, layers, options)

 trains and returns a network, trainedNet,
Just use a random Y.
 
Then train the resulting net using your own algorithm.
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!