且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Keras中使用训练有素的模型来预测输入图像?

更新时间:2023-12-02 08:49:52

keras预报_类(文档)输出一个类别预测的numpy数组.在您的模型案例中,哪一个是来自您的最后一层(softmax)的最高激活神经元的索引. [[0]]意味着您的模型预测您的测试数据为0类.(通常,您将传递多个图像,结果看起来像[[0], [1], [1], [0]])

keras predict_classes (docs) outputs A numpy array of class predictions. Which in your model case, the index of neuron of highest activation from your last(softmax) layer. [[0]] means that your model predicted that your test data is class 0. (usually you will be passing multiple image, and the result will look like [[0], [1], [1], [0]] )

您必须将实际标签(例如'cancer', 'not cancer')转换为二进制编码(对于癌症,0,对于非癌症",1)进行二进制分类.然后,您将[[0]]的序列输出解释为具有类标签'cancer'

You must convert your actual label (e.g. 'cancer', 'not cancer') into binary encoding (0 for 'cancer', 1 for 'not cancer') for binary classification. Then you will interpret your sequence output of [[0]] as having class label 'cancer'