DL4J:输入大小错误 - 预期矩阵

DL4J: Wrong input size - expected matrix

我正在尝试让我的网络评估 INDArray。这是我的网络: public class DQN {

private final int inputSize;
private final int outputSize;
private final MultiLayerNetwork network;


public DQN(int inputSize, int outputSize){

    this.inputSize = inputSize;
    this.outputSize = outputSize;

    MultiLayerConfiguration config = setConfig();
    this.network = new MultiLayerNetwork(config);
    this.network.init();
}

private MultiLayerConfiguration setConfig(){
    return new NeuralNetConfiguration.Builder()
            .seed(12345)
            .weightInit(WeightInit.XAVIER)
            .updater(new AdaGrad(0.5))
            .activation(Activation.RELU)
            .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
            .l2(0.0001)
            .list()
            .layer(0, new DenseLayer.Builder().nIn(this.inputSize).nOut(250).weightInit(WeightInit.XAVIER).activation(Activation.RELU) //First hidden layer
                    .build())
            .layer(1, new OutputLayer.Builder().nIn(250).nOut(this.outputSize).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX) //Output layer
                    .lossFunction(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
                    .build())
            .build();
}

public INDArray evaluate(INDArray vec){
    return this.network.output(vec);
}

}

不幸的是,每当我尝试用我的 INDArray 调用评估时,我得到:

Exception in thread "Thread-2" org.deeplearning4j.exception.DL4JInvalidInputException: Input that is not a matrix; expected matrix (rank 2), got rank 1 array with shape [23]. Missing preprocessor or wrong input type? (layer name: layer0, layer index: 0, layer type: DenseLayer)
    at org.deeplearning4j.nn.layers.BaseLayer.preOutputWithPreNorm(BaseLayer.java:308)
    at org.deeplearning4j.nn.layers.BaseLayer.preOutput(BaseLayer.java:291)
    at org.deeplearning4j.nn.layers.BaseLayer.activate(BaseLayer.java:339)
    at org.deeplearning4j.nn.layers.AbstractLayer.activate(AbstractLayer.java:258)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.outputOfLayerDetached(MultiLayerNetwork.java:1303)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2415)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2378)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2369)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2356)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2452)
    at wmaclean.rl.dqn.DQN.evaluate(DQN.java:51)

我的输入是具有 23 个元素的 1 阶向量,但网络似乎需要一个矩阵。有谁知道为什么?谢谢:)

找到我的问题。对于遇到类似问题的任何人,请确保在创建 INDArray 时指定形状:

Nd4j.create(data, **new int[]{1, vectorSizeCount}**)