import os, sys os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" import tensorflow as tf # v2.5.0 from tensorflow import keras def load_image(f): return tf.io.decode_image(tf.io.read_file(f), channels=1, dtype=tf.float32) with tf.device("/CPU:0"): model = tf.keras.models.load_model("model") image = tf.expand_dims(load_image(sys.argv[1]), axis=0) results = model.predict(image)[0] names = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck", "flag"] for name, result in zip(names, results): print(f"{name:10} {result*100:6.2f} %")