Initialize a Neural Network from layers but do NOT train

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.

 採用された回答

Greg Heath
Greg Heath 2017 年 9 月 8 日

0 投票

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.
Hope this helps.
Thank you for formally accepting my answer
Greg

2 件のコメント

Nikola Kovachki
Nikola Kovachki 2017 年 9 月 8 日
Yeah this was my thought too, but it just seemed hacky. I guess it's the only way to go. Thanks!
jim peyton
jim peyton 2018 年 1 月 10 日
In case MATLAB developers are listening, I second that. It's a real use-case.
I'm working with hand-engineered filters and transfer learning.

サインインしてコメントする。

その他の回答 (1 件)

Vla Ser
Vla Ser 2020 年 10 月 13 日

0 投票

https://www.mathworks.com/help/deeplearning/ref/assemblenetwork.html - you can use assemble network to create it from list of layers.

1 件のコメント

Royi Avital
Royi Avital 2021 年 12 月 2 日
For DAGNetwork I get an error that weights are not initialized. Have you solved this?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by