[英]DL4J - Is there a way to restrict the prediction of a model
I trained a Mnist model with DL4J.我用 DL4J 训练了一个 Mnist 模型。 When I use this model in inference mode:当我在推理模式下使用这个模型时:
INDArray prediction = myModel.output(myINDArrayImage);
That gives me a prediction in an INDArray
, it works properly.这给了我一个INDArray
的预测,它可以正常工作。 The size of this INDArray
is equal to number of output on my OutputLayer
model.此INDArray
的大小等于我的OutputLayer
模型上的输出数量。
Is there a way to restrict prediction to a character base?有没有办法将预测限制为字符库? ie somethings like this:即像这样的东西:
INDArray prediction = myModel.output(myINDArrayImage, charactersPossible);
Where charactersPossible
is the list of possible output indexes?哪里charactersPossible
是可能的输出索引列表?
You can create an INDArray (using Nd4j.create(double[])) with 1.0 for possible characters and 0.0 for not-possible characters.您可以创建一个 INDArray(使用 Nd4j.create(double[])),其中可能的字符为 1.0,不可能的字符为 0.0。 Then multiply that with the prediction INDArray, and then Nd4j.argMax the result.然后将其与预测 INDArray 相乘,然后将结果与 Nd4j.argMax 相乘。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.