Output result of prediction

This commit is contained in:
Heiko J Schick
2020-10-22 14:34:38 +02:00
parent 0a5635fe85
commit fb3edbbf64
+20 -15
View File
@@ -138,6 +138,16 @@ def train_lenet5(model):
validation_data=validation_generator, validation_steps=validation_steps,
shuffle=True, callbacks=[tensorboard])
def print_netout(i, netout, maximum_value):
"""
Prints the netout of LeNet-5.
"""
print("[%.4d] : [%.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f] = >>> %d <<<"
% (i,
netout[0], netout[1], netout[2], netout[3], netout[4],
netout[5], netout[6], netout[7], netout[8], netout[9],
maximum_value))
def main():
"""
Defined starting point of source code.
@@ -160,10 +170,9 @@ def main():
print('Number of test images:', test['features'].shape[0])
# Step 4:
# Display some images
# display_image(train, 0)
# display_image(train, 1)
# display_image(train, 2)
# Display three images of training dataset
for i in range(3):
display_image(train, i)
# Step 5:
# Plot information about the training data
@@ -198,28 +207,24 @@ def main():
# Train and save the LeNet-5 model
# train_lenet5(model)
# model.save('lenet5.h5')
model = load_model('lenet5.h5')
# Step 9:
# Print results
# PEvaluate with test data and print results
score = model.evaluate(test['features'], to_categorical(test['labels']))
print('Test loss:', score[0])
print('Test accuracy:', score[1])
# Step 10:
# Execute model and predict results
# display_image(test, 0)
# display_image(test, 1)
# display_image(test, 2)
netouts = model.predict(test['features'])
maximum_values = netouts.argmax(axis=1)
for i, netout in enumerate(netouts):
print("%d: %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f"
% (i, netout[0], netout[1], netout[2], netout[3], netout[4],
netout[5], netout[6], netout[7], netout[8], netout[9]))
# Step 11:
# Investigate ten predictions (randomly selected)
for i in np.random.choice(np.arange(0, len(test['labels'])), size=(10,)):
print_netout(i, netouts[i], maximum_values[i])
display_image(test, i)
if __name__ == "__main__":
main()