import tensorflow as tf import inference image_size = 128 # 输入层图片大小 #

1) # 再把数据格式转换成能运算的float32 decode_image =
tf.image.convert_image_dtype(decode_image, tf.float32) # 转换成指定的输入格式形状 image =
tf.reshape(decode_image, [-1, image_size, image_size, 1]) #

inference.inference(image, train=False, regularizer=None) # 利用softmax来获取概率
probabilities = tf.nn.softmax(test_logit) # 获取最大概率的标签位置 correct_prediction =
tf.argmax(test_logit, 1) # 定义Savar类 saver = tf.train.Saver() with tf.Session()
as sess: sess.run((tf.global_variables_initializer(),
tf.local_variables_initializer())) # 加载检查点状态，这里会获取最新训练好的模型 ckpt =
tf.train.get_checkpoint_state(MODEL_SAVE_PATH) if ckpt and
ckpt.model_checkpoint_path: # 加载模型和训练好的参数 saver.restore(sess,
ckpt.model_checkpoint_path) print("加载模型成功：" + ckpt.model_checkpoint_path) #

ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1] # 获取预测结果
probabilities, label = sess.run([probabilities, correct_prediction]) # 获取此标签的概率
probability = probabilities[0][label] print("After %s training
step(s),validation label = %d, has %g probability" % (global_step, label,
probability)) else: print("模型加载失败！" + ckpt.model_checkpoint_path)

（标签为3，概率为0.984478）

3对应小写d，识别正确。

（End）