简体   繁体   English

如何使用模型(.h5)查看 model 预测答案和真实 output?

[英]How can I see the model predicted answer and real output using model(.h5)?

I made my simple image classification model(classification.h5) by using CNN and I am hoping to see whether my model is working properly.我使用 CNN 制作了简单的图像分类模型(classification.h5),我希望看看我的 model 是否工作正常。

My CNN model is:我的 CNN model 是:

from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
model = Sequential()

model.add(Conv2D(16, (3, 3), activation='relu', strides=(1, 1), 
    padding='same',input_shape=input_shape))
model.add(MaxPool2D((2, 2)))
model.add(Dropout(0.5))

model.add(Conv2D(32, (3, 3), activation='relu', strides=(1, 1), 
    padding='same'))
model.add(MaxPool2D((2, 2)))
model.add(Dropout(0.5))

model.add(Conv2D(412, (13, 13), strides=(1, 1), padding = 'same', activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Dropout(0.5))

model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(64, activation='relu'))
model.add(Dense(4, activation='softmax'))

model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['acc'])
    

The model worked well. model 运行良好。 For the next step, I tried to see if this model really works well but I am lost how actually I can see the real result.对于下一步,我试图看看这个 model 是否真的运作良好,但我迷失了如何才能看到真正的结果。

What I want to try to see is shown below:我想尝试查看的内容如下所示:

model prediction = 'Model predicted answer' model prediction = '模型预测答案'

Real Answer = 'Real answer'真实答案 = '真实答案'

How can I write the code for this output?我该如何编写这个 output 的代码?

  1. Upload the saved model:上传保存的 model:
saved_model = keras.models.load_model("Model_Name.h5")
  1. Prepare your data (preprocessing or reshaping)准备数据(预处理或重塑)

  2. Do your predictions:做你的预测:

saved_model.predict(data)

Note: You can save a model like: model.save("Model_Name.h5")注意:您可以像这样保存 model: model.save("Model_Name.h5")

to see your model really worked or not you have to test out predictions on the data which was not used in training so you have to do something like要查看您的 model 是否真的有效,您必须测试未在训练中使用的数据的预测,因此您必须执行类似的操作

predicted_values = model.predict(data_not_used_in_training)预测值 = model.predict(data_not_used_in_training)

compare these predicted values with the real values of this data and apply metrics将这些预测值与该数据的实际值进行比较并应用指标
check this out on how to make predictions link查看有关如何进行预测的链接

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM