change 'classWeights' in unetLayers

조회 수: 7 (최근 30일)
Marco Festugato
Marco Festugato 2019년 9월 16일
댓글: Timothy Lee 2020년 6월 8일
Hello,
im using Unet to perform semantic segmentation (I want to segment liver metastasis). I want to weight 'more' the pixels of the metastasis respect to the background but I can't manage to do it...
Code for creating unet architecture:
lgraph = unetLayers(imageSize, numClasses, 'EncoderDepth', 4);
How can I change the 'classWeights' in lgraph.Layers(end).pixelClassificationLayer in order to do this??
If, for example, I do this:
lgraph.Layers(end).pixelClassificationLayer.classWeights = [2, 0.5];
I receive an error telling me that i have first to put the 'labels' to the 'classes' options in lgraph.Layers(end), but if i do this:
lgraph.Layers(end) = {'metastasis', 'background'};
I receive an error telling that that layer is in 'read only' mode....
Please im getting crazy...
Thanks in advance for any help!

채택된 답변

Raunak Gupta
Raunak Gupta 2019년 9월 19일
Hi,
The unetLayers object in MATLAB is in read only mode and we cannot change the properties of layers as such. You may remove the last layer which is the Segmentation-Layer and can add a new Segmentation-Layer with the properties that are mentioned. Following Code will help.
% Last Layer Name is 'Segmentation-Layer'
% for checking layer name use :- lgraph.Layers
lgraph = removeLayers(lgraph,'Segmentation-Layer');
layerlast = pixelClassificationLayer('Classes',{'metastatis','background'},'ClassWeights',[2,0.5],'Name','New_segmentation_Layer');
layer_to_add = [layerlast];
lgraph = addLayers(lgraph,layer_to_add);
Reference to the functions that are used removeLayers, pixelClassificationLayer, addLayers.
  댓글 수: 2
Marco Festugato
Marco Festugato 2019년 9월 19일
It worked! Thank u so much :)
Timothy Lee
Timothy Lee 2020년 6월 8일
By using pixelClassificationLayer with class weights, is this the same as implementing a custom weighted classification layer, as shown in this example:

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by