Model with softmax output layer not outputing probabilities but just 1 and 0
Author: crorafCreated May 6, 2024Updated Jul 8, 2026
Labelscomp:node.jscomp:modelstype:othersstat:contributions welcome
I'm testing the model provided in node-js example https://github.com/tensorflow/tfjs-examples/blob/master/mnist-node/model.js to classify images of numbers into classes 0 to 9.
It is a tf.sequential() model, and its final layer is model.add(tf.layers.dense({ units: 10, activation: "softmax" }));
Therefore the prediction should output probabilities per class, but this is not happening. Instead only 0s and 1s (in a one-hot fashion) are outputed in the following logging.
const predictions = model.predict(data);
predictions.print();How to get the probabilities of specific image belonging to specific class
Source: tensorflow/tfjs