need help to convert to a dlnetwork
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Ben
le 18 Sep 2023
Modifié(e) : Ben
le 18 Sep 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);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!