need help to convert to a dlnetwork

18 visualizzazioni (ultimi 30 giorni)
Sri Kapali
Sri Kapali il 15 Set 2023
Modificato: Ben il 18 Set 2023
I have this existing code
image = randi(255, [3,3,4]);
% create adder only network
inLayer = imageInputLayer(size(image), 'Name', 'data', 'Normalization', 'none');
addLayer = additionLayer(2, 'Name', 'add');
outLayer = regressionLayer('Name','output');
lgraph = layerGraph([inLayer, addLayer, outLayer]);
lgraph = connectLayers(lgraph, 'data', 'add/in2');
snet = assembleNetwork(lgraph);
I need to convert this to a dlnetwork and then train the dlnetwork using trainnet to replace the last regression output layer. How can I achieve the same?

Risposta accettata

Ben
Ben il 18 Set 2023
Modificato: Ben il 18 Set 2023
The workflow for dlnetwork and trainnet would be something like the following:
image = randi(255,[3,3,4]);
% create network
net = [
imageInputLayer(size(image),Name="data",Normalization="none")
additionLayer(2,Name="add")];
% create as uninitialized so you can hook up the 2nd input to additionLayer before initializing
net = dlnetwork(net,Initialize = false);
net = connectLayers(net,"data","add/in2");
% initialize
net = initialize(net);
% train
opts = trainingOptions("adam");
% regressionLayer is not used, to specify loss you can use "mse" in trainnet
trainnet(image,image,net,"mse",opts);

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by