1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| from __future__ import absolute_import, division, print_function
import os import tensorflow as tf import tensorflow.contrib.eager as tfe os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' tf.compat.v1.enable_eager_execution()
file_path = './data/model' model = tf.keras.models.load_model(file_path + "/iris-model")
class_names = ['Iris setosa', 'Iris versicolor', 'Iris virginica']
predict_dataset = tf.convert_to_tensor([ [5.1, 3.3, 1.7, 0.5, ], [5.9, 3.0, 4.2, 1.5, ], [6.9, 3.1, 5.4, 2.1] ])
predictions = model(predict_dataset)
for i, logits in enumerate(predictions): class_idx = tf.argmax(logits).numpy() p = tf.nn.softmax(logits)[class_idx] name = class_names[class_idx] print("Example {} prediction: {} ({:4.1f}%)".format(i, name, 100*p))
|