Output result of prediction
This commit is contained in:
@@ -138,6 +138,16 @@ def train_lenet5(model):
|
|||||||
validation_data=validation_generator, validation_steps=validation_steps,
|
validation_data=validation_generator, validation_steps=validation_steps,
|
||||||
shuffle=True, callbacks=[tensorboard])
|
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():
|
def main():
|
||||||
"""
|
"""
|
||||||
Defined starting point of source code.
|
Defined starting point of source code.
|
||||||
@@ -160,10 +170,9 @@ def main():
|
|||||||
print('Number of test images:', test['features'].shape[0])
|
print('Number of test images:', test['features'].shape[0])
|
||||||
|
|
||||||
# Step 4:
|
# Step 4:
|
||||||
# Display some images
|
# Display three images of training dataset
|
||||||
# display_image(train, 0)
|
for i in range(3):
|
||||||
# display_image(train, 1)
|
display_image(train, i)
|
||||||
# display_image(train, 2)
|
|
||||||
|
|
||||||
# Step 5:
|
# Step 5:
|
||||||
# Plot information about the training data
|
# Plot information about the training data
|
||||||
@@ -198,28 +207,24 @@ def main():
|
|||||||
# Train and save the LeNet-5 model
|
# Train and save the LeNet-5 model
|
||||||
# train_lenet5(model)
|
# train_lenet5(model)
|
||||||
# model.save('lenet5.h5')
|
# model.save('lenet5.h5')
|
||||||
|
|
||||||
model = load_model('lenet5.h5')
|
model = load_model('lenet5.h5')
|
||||||
|
|
||||||
# Step 9:
|
# Step 9:
|
||||||
# Print results
|
# PEvaluate with test data and print results
|
||||||
score = model.evaluate(test['features'], to_categorical(test['labels']))
|
score = model.evaluate(test['features'], to_categorical(test['labels']))
|
||||||
print('Test loss:', score[0])
|
print('Test loss:', score[0])
|
||||||
print('Test accuracy:', score[1])
|
print('Test accuracy:', score[1])
|
||||||
|
|
||||||
# Step 10:
|
# Step 10:
|
||||||
# Execute model and predict results
|
# Execute model and predict results
|
||||||
|
|
||||||
# display_image(test, 0)
|
|
||||||
# display_image(test, 1)
|
|
||||||
# display_image(test, 2)
|
|
||||||
|
|
||||||
netouts = model.predict(test['features'])
|
netouts = model.predict(test['features'])
|
||||||
|
maximum_values = netouts.argmax(axis=1)
|
||||||
|
|
||||||
for i, netout in enumerate(netouts):
|
# Step 11:
|
||||||
print("%d: %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f"
|
# Investigate ten predictions (randomly selected)
|
||||||
% (i, netout[0], netout[1], netout[2], netout[3], netout[4],
|
for i in np.random.choice(np.arange(0, len(test['labels'])), size=(10,)):
|
||||||
netout[5], netout[6], netout[7], netout[8], netout[9]))
|
print_netout(i, netouts[i], maximum_values[i])
|
||||||
|
display_image(test, i)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user