change outputlayer in layergraph object
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello,
I have a layerGraph object and I need to remove the output layer because it is not relevant and it is not supported by Deep Learning HDL Toolbox.
I removed another layer and then make the corresponding connection but the output layer is different because I need to change the 'OutputNames' or set the out output layer in other way. However, 'OutputNames' property is read only.
I also tried to replace the last layer by the previous one and remove the previous layer but I get the same result
find in the following link the layerGraph object layers.mat
Is there any way to change the output layer in a layerGraph object?
Thank you in advance.
채택된 답변
Matt J
2023년 5월 18일
For example,
lgraph=layerGraph(regressionLayer)
lgraph =
LayerGraph with properties:
InputNames: {1×0 cell}
OutputNames: {'regressionoutput'}
Layers: [1×1 nnet.cnn.layer.RegressionOutputLayer]
Connections: [0×2 table]
layers=lgraph.Layers;
layers(end).Name='newName';
lgraph=layerGraph(layers)
lgraph =
LayerGraph with properties:
InputNames: {1×0 cell}
OutputNames: {'newName'}
Layers: [1×1 nnet.cnn.layer.RegressionOutputLayer]
Connections: [0×2 table]
댓글 수: 8
If I'm not wrong, it only changes the name of the layer and biulds a new layerGraph object with the same layer but with a different name.
I tried something similar, replacing the last layer and replacing its name but layerGraph's 'OutputNames' property changes to be empty and last layer seems not no be connected or set as output layer
I need to remove the 'BinaryCrossEntropyRegressionLaye_reshape' and make 'conv2d_8_sigmoid' the output layer.
--> 
Before replacing/removing last layer
LayerGraph with properties:
Layers: [22×1 nnet.cnn.layer.Layer]
Connections: [21×2 table]
InputNames: {'input_1'}
OutputNames: {'BinaryCrossEntropyRegressionLayer_reshape'}
After replacing/removing last layer
LayerGraph with properties:
Layers: [21×1 nnet.cnn.layer.Layer]
Connections: [20×2 table]
InputNames: {'input_1'}
OutputNames: {1×0 cell}
However, if i read the name of the last layer it is nt empty (you suggested changing the last layer name but it doesn't change 'outputNames' porperty):
layers.Layers(end).Name
ans =
'conv2d_8_sigmoid'
The problem comess when I try to assemble a NN with 'assembleNetwork' function
Network: Missing output layer. The network must have at least one output layer.
Invalid network.
Caused by:
Network: Missing output layer. The network must have at least one output layer.
Layer 'conv2d_8_sigmoid': Unconnected output. Each layer output must be connected to the input of another layer.
In addition I trid to replace the last layer with a copy of the previous layer changing its name to 'BinaryCrossEntropyRegressionLayer_reshape' but I get 'Output Names' property empty
outLayer=layers.Layers(end-1);
outLayer.Name = layers.Layers(end).Name;
layers = replaceLayer(layers, layers.Layers(end).Name, outLayer)
layers =
LayerGraph with properties:
Layers: [22×1 nnet.cnn.layer.Layer]
Connections: [21×2 table]
InputNames: {'input_1'}
OutputNames: {1×0 cell}
The point how change the connection of the last layer with the output layer or change the reference of the output layer.
Rubén
2023년 5월 19일
I fixed it replacing last layer by a classification layer
If I'm not wrong, it only changes the name of the layer and biulds a new layerGraph object with the same layer but with a different name.
Yes, it was an example. Basically, if you extract the Layers property, you can manipulate the layer array freely and build a new graph. It was not clear from your post precisely what change you are trying to make but it should still apply.
I fixed it replacing last layer by a classification layer
I'm glad, but please Accept-click the answer if it resolved your question.
Rubén
2023년 5월 21일
So the problem was that only classification or regression layers are supported to be output layers in a layer graph object, wasn't it? what about the 'BinaryCrossEntropyRegressionLayer_reshape' I had?
So the problem was that only classification or regression layers are supported to be output layers in a layer graph object, wasn't it?
I don't see how the choice of output layer would have been the issue. A layer graph does not even have to have an output layer. It can even consist of a single convolutional layer, e.g.,
lg=layerGraph(convolution2dLayer([1,1],1))
lg =
LayerGraph with properties:
InputNames: {1×0 cell}
OutputNames: {1×0 cell}
Layers: [1×1 nnet.cnn.layer.Convolution2DLayer]
Connections: [0×2 table]
Rubén
2023년 5월 21일
In that example 'IutputNames' and 'OutputNames' properties are 1x0 cell. That means that are empty and input and output layers are not defined. I think you will get the same error whe you assemble that layerGraph object with 'assembleNetwork' function, coudl you check it?
It will definitely given an error because it has no input and output layers, but that is not the point. Your original question was how to change the output name property of an output layer within an existing layerGraph and my original answer demonstrated how to do that.
If the question is about making predictions in a network without using an output layer, you can do it by using dlnetwork instead of assembleNetwork.
cl=convolution2dLayer([3,3],1 ,'Padding','same','Weights',rand(3),'Bias',0);
net=dlnetwork(cl,networkDataLayout([8,8,1],'SSC'));
net.predict(dlarray(rand(8),'SSC'))
ans =
8(S) × 8(S) × 1(C) single dlarray
1.9330 1.6235 1.4864 1.6687 2.1314 1.7076 1.5632 1.1103
2.1311 2.7175 1.8709 3.1219 2.9320 2.4912 2.6637 1.8686
2.0587 2.2242 2.5526 2.5633 2.7993 2.7756 2.4032 1.2422
1.8285 2.6174 1.9562 2.4646 2.5606 2.4817 2.1627 1.1586
1.9782 2.2336 2.9013 2.7397 2.2003 2.0638 1.7779 1.1409
1.0009 2.6439 2.3893 3.0688 2.0361 2.4400 2.3526 1.9205
1.3489 2.1934 2.7162 2.8103 2.6220 2.7962 2.9462 2.1174
1.0200 1.3155 1.1040 1.8461 1.8275 1.5256 2.7954 2.0552
Rubén
2023년 5월 24일
I'm sorry but the original question was how to change the output layer itself. Maybe the misunderstanding comes because the 'OutputNames' property. Anyway, question is solved. Thank you
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
