need help to convert to a dlnetwork

14 次查看(过去 30 天)
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?

采纳的回答

Ben
Ben 2023-9-18
编辑:Ben 2023-9-18
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 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by