Prediction on a pre-trained neural network

I would like to define my own neural network and do predictions on it without performing any training.
Something like:
  1. Define layers
  2. Set the weights and biases of each layer (based on a trained model from another context)
  3. Perform prediction
An example of 1) is below
layers = [
imageInputLayer([32 32 1])
convolution2dLayer(5,6)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(5,6)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(80)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(6)
batchNormalizationLayer
];
Any pointers on 2) and 3) would be appreciated.

 채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2020년 3월 21일

0 개 추천

Using weights of different network to the current network:
for 2 networks net1 & net2, copy the layers to some variable
layers = net1.Layers;
layers(net1layerindex).Weights(net1index) = net2.Layers(net2layerindex).Weights(net2index);
Let's say you want to set weights of a channel of a convolution2dLayer to zeros(channelDimension)
layers(convLayerIndex).Weights(:,:,channelIndex) = zeros(channelDimension)
%also
layers(convLayerIndex).Weights(:,:,channelIndex,Index) = zeros(respectiveDimension)
Use the above layers to create a DAG or a Series network. You can also refer to the documentation of the assembleNetwork function which helps creating deep learning networks from layers without training.
You can also set the Learning factor for a layer as follows:
layer.WeightLearnRateFactor = 0;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2020년 3월 18일

댓글:

2020년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by