简体   繁体   中英

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.

My CNN model is:

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. 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.

What I want to try to see is shown below:

model prediction = 'Model predicted answer'

Real Answer = 'Real answer'

How can I write the code for this output?

  1. Upload the saved 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")

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

predicted_values = 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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