Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Z
Z il 22 Set 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.

Accedi per commentare.

Risposte (1)

Gagan Agarwal
Gagan Agarwal il 30 Ago 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 Commento
Z
Z il 30 Ago 2023
Modificato: Z il 30 Ago 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'.

Accedi per commentare.

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by