tensorflow练习9:图像分类器
来源:互联网 发布:安华卫浴知乎 编辑:程序博客网 时间:2024/06/13 11:59
这一节继续使用谷歌的image_retain作为模型进行训练。下载文件:
https://github.com/tensorflow/tensorflow。
使用examples中的image_retraining进行训练:
运行命令:
python tensorflow/tensorflow/examples/image_retraining/retrain.py --bottleneck_dir bottleneck --how_many_training_steps 4000 --model_dir model --output_graph output_graph.pb --output_labels output_labels.txt --image_dir girl_types/
训练一段时间后,得到输出文件:output_graph.pb与output_labels.txt。使用训练好的文件:
import tensorflow as tfimport sys# 命令行参数,传入要判断的图片路径image_file = sys.argv[1]#print(image_file)# 读取图像image = tf.gfile.FastGFile(image_file, 'rb').read()# 加载图像分类标签labels = []for label in tf.gfile.GFile("output_labels.txt"): labels.append(label.rstrip())# 加载Graphwith tf.gfile.FastGFile("output_graph.pb", 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) tf.import_graph_def(graph_def, name='')with tf.Session() as sess: softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') predict = sess.run(softmax_tensor, {'DecodeJpeg/contents:0': image}) # 根据分类概率进行排序 top = predict[0].argsort()[-len(predict[0]):][::-1] for index in top: human_string = labels[index] score = predict[0][index] print(human_string, score)
阅读全文
0 0
- tensorflow练习9:图像分类器
- 图像分类练习
- tensorflow 图像分类实战解析
- TensorFlow-Slim图像分类库
- 简单的图像分类练习
- TensorFlow练习1: 对评论进行分类
- TensorFlow练习2: 对评论进行分类
- TensorFlow练习1: 对评论进行分类
- tensorflow练习1:利用神经网络进行分类
- Tensorflow练习1-对评论进行分类
- tensorflow 图像分类实战解析(上)
- tensorflow图像分类实战解析(下)
- TensorFlow进阶:CNN对CIFAR10图像分类
- tensorflow 学习:用CNN进行图像分类
- 使用TensorFlow-Slim进行图像分类
- tensorflow+图像分类使用的一些错误
- TensorFlow小试牛刀(1):CNN图像分类
- 如何重新训练Tensorflow图像分类模型
- 公鸡打鸣
- Python的基础语法及使用
- 实验楼Linux基础入门(新版)- 备份日志
- 标签选择器
- ipython报错
- tensorflow练习9:图像分类器
- python中的property()
- 文章标题
- 登录字符验证码
- PnP 单目相机位姿估计(一):初识PnP问题
- 详解KMP算法
- UVA.10820 Send A Table (欧拉函数)
- caffe的再次编译
- GDI常用函数