使 DL4J 分类器得分 return

Make DL4J classifier return score

我正在玩 DeepLearning4J and I wonder how I can make a classifier return a score instead of a label. Suppose I use the code from the linear classifier tutorial,我想让 ANN return 将给定训练示例标记为 0 或 1 的概率。当前配置看起来如下如下:

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
        .seed(123)
        .iterations(1)
        .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
        .learningRate(0.01)
        .updater(Updater.NESTEROVS)
        .momentum(0.9)
        .list()
        .layer(0, new DenseLayer.Builder()
                .nIn(2)
                .nOut(20)
                .weightInit(WeightInit.XAVIER)
                .activation(Activation.RELU)
                .build())
        .layer(1, new OutputLayer.Builder(LossFunction.NEGATIVELOGLIKELIHOOD)
                .nIn(20)
                .nOut(2)
                .weightInit(WeightInit.XAVIER)
                .activation(Activation.SOFTMAX)
                .build())
        .pretrain(false)
        .backprop(true)
        .build();

使用model.output .

你会得到一个 ndarray (http://nd4j.org/tensor)

它在输出上使用 softmax,这意味着您得到批量大小 x 标签输出数量。