简体   繁体   English

如何使用训练有素的Keras模型进行新的预测?

[英]How can I get use of trained Keras model to make new predictions?

i am a newbee of Keras. 我是Keras的新人。 When i am done with the Iris classification tutorial, i just confused with this, since we encoded those 3 kinds of iris flowers, for example, one-hot encoding. 当我完成Iris分类教程时,我只是对此感到困惑,因为我们编码了这3种鸢尾花,例如,单热编码。 We should get 3 orthogonal vectors right? 我们应该得到3个正交向量吗?

setosa      [1 0 0]
versicolor  [0 1 0]
virginica   [0 0 1]

my model is the same as tutorial : 我的模型与教程相同:

http://machinelearningmastery.com/multi-class-classification-tutorial-keras-deep-learning-library/

and my question is although i got the result: 我的问题是虽然我得到了结果:

Baseline: 95.33% (4.27%)

but when i call the trained deep network model: 但当我打电话给训练有素的深层网络模型时:

prediction = baseline_model().predict(X)

where X is the orginal input when i trained the network 其中X是我训练网络时的原始输入

i got a very wired predictions such that: 我有一个非常有线的预测,这样:

print prediction
0,0,0
0,0,0
0,0,0
0,0,0

with all zero vectors, and i am supposed to get some one-hot encoded result right? 所有零向量,我应该得到一些单热编码结果吗? to identify which class the flower should be. 确定花应该是哪一类。

so how can i make use of my trained Keras model while im inputting the same input X and get the classify result to plot a graph?? 那么我如何利用我训练过的Keras模型同时输入相同的输入X并获得分类结果来绘制图形?

You need to train your network, and only then you can use it for prediction. 您需要训练您的网络,然后才能将其用于预测。 Using the notations from the tutorial, you may do: 使用教程中的符号,您可以:

estimator = KerasClassifier(build_fn=baseline_model, nb_epoch=200, batch_size=5, verbose=0)
X_train, X_test, Y_train, Y_test = train_test_split(X, dummy_y, test_size=0.33, random_state=seed)
estimator.fit(X_train, Y_train)
predictions = estimator.predict(X)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用保存在 HDF5 文件中的 Keras 训练模型进行预测? - How can I use a Keras trained model saved in a HDF5 file to make predictions? 使用经过训练的 Keras 模型对新的 csv 数据进行预测 - Using a trained Keras model to make predictions on new csv data 如何在Tensorflow输入管道中根据受过训练的模型进行预测? - How can I make predictions from a trained model inside a Tensorflow input pipeline? 如何基于训练有素的Tensorflow模型进行预测? - How to make predictions based on a trained Tensorflow Model? 训练 model 后,从 Keras/Tensorflow 获取预测 - Get predictions from Keras/Tensorflow once model is trained 如何使用 PyTorch 在预训练模型上添加新层? (给出了 Keras 示例。) - How can I add new layers on pre-trained model with PyTorch? (Keras example given.) 在C#中获得Keras训练的模型预测 - Getting Keras trained model predictions in c# 如何使用现有CNN模型中的预训练权重在Keras中进行迁移学习? - How can I use pre-trained weights from an existing CNN model for transfer learning in Keras? 如何使用预训练网络对新音频文件进行预测? - How to make predictions on new audio files with pre-trained network? 如何在 keras 和 python 中保存和使用经过训练的模型 - How to save and use a trained model in keras and python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM