need help to convert to a dlnetwork

14 ビュー (過去 30 日間)
Sri Kapali
Sri Kapali 2023 年 9 月 15 日
編集済み: Ben 2023 年 9 月 18 日
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 Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by