How can I build a multitask learning model

8 次查看(过去 30 天)
AM MSR
AM MSR 2018-12-12
回答: Akshat 2024-11-12,20:58
How can I build a multitask learning model using a pretrained CNN

回答(1 个)

Akshat
Akshat 2024-11-12,20:58
You can build a multitask model using a pretrained CNN by removing the last few layers and replacing them with your custom layers serving the task you want to serve.
Here is an example in case you want to replace the last few layers to make a classification and regression model:
net = resnet50;
lgraph = layerGraph(net);
% Remove the last layers specific to the original task
lgraph = removeLayers(lgraph, {'fc1000', 'fc1000_softmax', 'ClassificationLayer_fc1000'});
% Add new task-specific layers
% Task 1: Classification
numClassesTask1 = 10;
classificationLayers = [
fullyConnectedLayer(numClassesTask1, 'Name', 'fc_task1')
softmaxLayer('Name', 'softmax_task1')
classificationLayer('Name', 'classification_output')];
% Task 2: Regression
regressionLayers = [
fullyConnectedLayer(1, 'Name', 'fc_task2')
regressionLayer('Name', 'regression_output')];
lgraph = addLayers(lgraph, classificationLayers);
lgraph = addLayers(lgraph, regressionLayers);
lgraph = connectLayers(lgraph, 'avg_pool', 'fc_task1');
lgraph = connectLayers(lgraph, 'avg_pool', 'fc_task2');
options = trainingOptions('sgdm', ...
'MiniBatchSize', 32, ...
'MaxEpochs', 10, ...
'InitialLearnRate', 0.001, ...
'Shuffle', 'every-epoch', ...
'Plots', 'training-progress', ...
'Verbose', false);
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Multicore Processor Targets 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by