导出推理图

python export_inference_graph.py \--alsologtostderr \--dataset_name=autohome \  #自定义数据集的名称--model_name=mobilenet_v2_140 \ #模型名字--image_size=224 \--output_file=angle/mobilenet_v2_140_224_inference.pb #待输出的推理图

冻结模型文件

python -m tensorflow.python.tools.freeze_graph \--input_graph=angle/mobilenet_v2_140_224_inference.pb \ #推理图--input_binary=true \--output_node_names=MobilenetV2/Predictions/Reshape_1 \ #根据不同模型确定各自的输出节点--input_checkpoint=angle/model/model.ckpt-10560 \  #训练的模型文件--output_graph=angle/model/frozen_angle8.pb   #导出的冻结图

使用冻结模型

import tensorflow as tf
import os
import numpy as np
import os, glob, cv2
import sys, argparse# First, pass the path of the image
dir_path = os.path.dirname(os.path.realpath(__file__))
image_path = sys.argv[1]
filename = dir_path + '/' + image_path
image_size = 224
num_channels = 3
images = []##  Reading the image using OpenCV
image = cv2.imread(filename)##   Resizing the image to our desired size and preprocessing will be done exactly as done during training
image = cv2.resize(image, (image_size, image_size), cv2.INTER_LINEAR)
images.append(image)
images = np.array(images, dtype=np.uint8)
images = images.astype('float32')
images = np.multiply(images, 1.0 / 255.0)
##   The input to the network is of shape [None image_size image_size num_channels].
## Hence we reshape.x_batch = images.reshape(1, image_size, image_size, num_channels)frozen_graph = "./angle/model/frozen_angle8.pb"
with tf.gfile.GFile(frozen_graph, "rb") as f:graph_def = tf.GraphDef()graph_def.ParseFromString(f.read())with tf.Graph().as_default() as graph:tf.import_graph_def(graph_def,input_map=None,return_elements=None,name="")
## NOW the complete graph with values has been restored
y_pred = graph.get_tensor_by_name("MobilenetV2/Predictions/Reshape_1:0")
## Let's feed the images to the input placeholders
x = graph.get_tensor_by_name("input:0")
y_test_images = np.zeros((1, 2))
sess = tf.Session(graph=graph)
### Creating the feed_dict that is required to be fed to calculate y_pred
feed_dict_testing = {x: x_batch}
result = sess.run(y_pred, feed_dict=feed_dict_testing)
print(result)

测试模型结果。

python svc_on_freeze.py head45_l.jpg  #当前模型识别车辆的8个角度信息,加上背景信息供9个值[[0.00551218 0.00247121 0.8145236  0.04009005 0.01283834 0.017873710.07377602 0.00181285 0.03110213]]

参考文献:

  1. TensorFlow-Slim image classification model library

  2. Freeze Tensorflow models and serve on web

tensorflow导出冻结图模型相关推荐

  1. [PaddleSeg源码阅读] PaddleSeg 导出静态图 export.py 文件中的道道

    周末去泰山玩♂耍,周六晚上10点半开始爬,周日上午10点26回到住的地方躺下,整整12个小时!! 我一个人爬完全程有些慢,不过起码我不是逃兵 下山到最后几段的时候,脸上摆出极其夸张和痛苦的表情,有几个 ...

  2. Tensorflow C++ 编译和调用图模型

    简介 最近在研究如何打通tensorflow线下 python 的脚本训练建模, 利用freeze_graph工具输出.pb图文件,之后再线上生产环境用C++代码直接调用预先训练好的模型完成预测的工作 ...

  3. Tensorflow + OpenCV4 安全帽检测模型训练与推理

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 开发环境 软件版本信息: Windows10 64位 Tensor ...

  4. 飞桨上线万能转换小工具,教你玩转TensorFlow、Caffe等模型迁移

    百度推出飞桨(PaddlePaddle)后,不少开发者开始转向国内的深度学习框架.但是从代码的转移谈何容易,之前的工作重写一遍不太现实,成千上万行代码的手工转换等于是在做一次二次开发. 现在,有个好消 ...

  5. 4模型导出_项目模型规范总结 游戏模型制作的注意事项

    点击上方"3D天工坊"关注我本期我们来总结一下模型规范导出等~ 1. 单位,比例统一 在建模型前先设置好单位,在同一场景中会用到的模型的单位设置必须一样,模型与模型之间的比例要正确 ...

  6. 图模型+Bert香不香?完全基于注意力机制的图表征学习模型Graph-Bert

    作者 | Jiawei Zhang.Haopeng Zhang.Congying Xia.Li Sun 译者 | 凯隐 编辑 | Jane 出品 | AI科技大本营(ID:rgznai100) [导读 ...

  7. Tensorflow |(5)模型保存与恢复、自定义命令行参数

    Tensorflow |(1)初识Tensorflow Tensorflow |(2)张量的阶和数据类型及张量操作 Tensorflow |(3)变量的的创建.初始化.保存和加载 Tensorflow ...

  8. ICLR 2019计算机视觉、NLP、图模型、对抗学习、表示学习和元学习

    https://www.toutiao.com/a6703123631590867459/ 原作者:Marina Vinyes 深度学习与NLP编译 关键词:Computer Vision, Natu ...

  9. 斯坦福-随机图模型-week2.1_

    title: 斯坦福-随机图模型-week2.1 tags: note notebook: 6- 英文课程-9-Probabilistic Graphical Models 1: Representa ...

最新文章

  1. oracle之Flash Recovery Area全面介绍
  2. [深度学习] 自然语言处理 --- Self-Attention(二) 动画与代码演示
  3. 公网可用的RTMP、RTSP测试地址(更新于2021年3月)
  4. Oracle删除用户与删除表
  5. Android 动画 Animator 家族
  6. 使用TypeScript正确键入Vuex
  7. python人工智能学习笔记_[Python] 人工智能与自然语言处理学习笔记(1)
  8. oracle 参数脚本,oracle 查看隐含参数脚本
  9. GBDT 算法:原理篇
  10. Pandas入门教程(四)
  11. [CF438D]The Child and Sequence
  12. java栈中存放_java栈存放什么?java堆存放什么?
  13. java项目-第91期基于ssm的蛋糕商城系统
  14. 一根网线连接两台电脑,从而实现数据的传输
  15. 中富之命能有多少钱_算命中富 算命的说我是中富命,谁可以帮忙解释下
  16. eSPI自学笔记(二):Perpheral Channel与Subtractive Decode
  17. 爱情故事:追忆似水流年 回味永恒的爱恋
  18. 我从冯·诺依曼计算机体系,追溯到了JVM,原来一切如此
  19. 掘金chrome插件安装失败怎么办?
  20. 英语对于程序员重要吗?

热门文章

  1. Powerpoint高级技巧
  2. WPS 万分位分隔符
  3. 百度新闻资讯类信息爬虫--统计一年内关键词新闻的条数
  4. 新版标准日本语高级_第3课
  5. 伪代码基本规范~呦呦呦
  6. Mac和Windows键盘对应关系
  7. 计算机80坐标转换经纬度,西安80坐标系(高斯投影)转经纬度(示例代码)
  8. 0321 复利计算—贷款
  9. 自媒体各大平台收益对比_自媒体哪些平台收益比较高?
  10. 计算机被格式化怎么找回资料,电脑分区文件被格式化误删了怎么恢复