Filter löschen
Filter löschen

For binary classification using a neural network, I want to enforce one output node instead of two output nodes

2 Ansichten (letzte 30 Tage)
I have a dataset consisting of a positive class and a negative class which I want to classifiy using a neural network (e.g. cancerous tumor or benign). I want to set the classification layer to a single node, either this class or that class. During training, MATLAB detects that the data contains two labels, and insists that I put two nodes at the output. How can I enforce one node at the output?
  1 Kommentar
Z
Z am 22 Sep. 2022
I learned that I needed to use a sigmoid instead of a softmax before the output layer. Now the issue is that I cannot use the built-in classification layer, and need to create a custom layer which uses the binary cross-entropy loss.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Gagan Agarwal
Gagan Agarwal am 30 Aug. 2023
Hi Z
In MATLAB, the default assumption is that your dataset contains multiple classes, and as a result, the output layer is automatically configured accordingly with the desired no of nodes to accommodate the corresponding classes.
However, if you specifically want to ensure that the output layer has only one node, you can achieve this by explicitly setting the size of the output layer to 1 using the following command:
net.layers{end}.size = 1;
Here, the variable 'net' represents your neural network.
  1 Kommentar
Z
Z am 30 Aug. 2023
Bearbeitet: Z am 30 Aug. 2023
Hello Gagan,
This command doesn't work.
For example, if I do
net=googlenet;
net.layers{end}.size = 1;
I get: Unrecognized method, property, or field 'layers' for class 'DAGNetwork'.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by