训练完模型肯定是要推理的啦~在这里提醒一下,训练时图像做了什么预处理推理时最好也同样做相应的预处理,否则预测结果会有意外收获,比如意外的差。
port tensorflow as tf
import numpy as np
import os
import resnet_v2 as resnet_v2
import tensorflow.contrib.slim as slim
import cv2
height,width=224,224
X=tf.placeholder(tf.float32,[None,height,width,3])
def Infer(checkpoint_path,image_path):
nameList=os.listdir(image_path)
with slim.arg_scope(resnet_v2.resnet_arg_scope()):
net, end_points = resnet_v2.resnet_v2_101(X,num_classes=3,is_training=False)
with tf.Session() as sess:
saver=tf.train.Saver(tf.global_variables())
saver.restore(sess,checkpoint_path)
num_classes =3
k=1
corret=0
wrong=0
Info=[]
&nb

本文介绍了如何使用ResNet_v2_101模型进行图像分类的推理过程。在推理时需要注意与训练时相同的预处理步骤,以避免预测结果出错。代码示例展示了加载模型、处理图像并获取预测结果的详细步骤。
最低0.47元/天 解锁文章
815

被折叠的 条评论
为什么被折叠?



