操作过程:

1. 查看mobilenet的variables

loaded = tf.saved_model.load('mobilenet')
print('MobileNet has {} trainable variables: {},...'.format(
len(loaded.trainable_variables),
', '.join([v.name for v in loaded.trainable_variables[:5]])))
trainable_variable_ids = {id(v) for v in loaded.trainable_variables}
non_trainable_variables = [v for v in loaded.variables if id(v) not in trainable_variable_ids]
print('MobileNet also has {} non-trainable variables: {}, ...'.format(
len(non_trainable_variables),
', '.join([v.name for v in non_trainable_variables[:3]])))

输出:输出trainable_variables的后5个variables,non_trainable_variables的后3个variables.

MobileNet has  trainable variables: conv1/kernel:, conv1_bn/gamma:, conv1_bn/beta:, conv_dw_1/depthwise_kernel:, conv_dw_1_bn/gamma:,...
MobileNet also has non-trainable variables: conv1_bn/moving_mean:, conv1_bn/moving_variance:, conv_dw_1_bn/moving_mean:, ...

但是这种方法输出model/detector模型的variables却出错;

Traceback (most recent call last):
File "inspect_saved_model.py", line , in <module>
len(facebox_model.trainable_variables),
AttributeError: '_UserObject' object has no attribute 'trainable_variables'

原因还没找出来,有知道的可以私信博主哈~

2. 使用命令行查看模型的signatures

usage: saved_model_cli show [-h] --dir DIR [--all]
[--tag_set TAG_SET] [--signature_def SIGNATURE_DEF_KEY]

例如

saved_model_cli show --dir mobilenet/ --all
or
saved_model_cli show --dir model/detector/ --tag_set serve --signature_def serving_default

输出

(tf_test) ~/workspace/test_code/github_test/faceboxes-tensorflow$ saved_model_cli show --dir model/detector --all

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['__saved_model_init_op']:
The given SavedModel SignatureDef contains the following input(s):
The given SavedModel SignatureDef contains the following output(s):
outputs['__saved_model_init_op'] tensor_info:
dtype: DT_INVALID
shape: unknown_rank
name: NoOp
Method name is: signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['images'] tensor_info:
dtype: DT_FLOAT
shape: (-, -, -, -)
name: serving_default_images:
The given SavedModel SignatureDef contains the following output(s):
outputs['boxes'] tensor_info:
dtype: DT_FLOAT
shape: (-, , )
name: StatefulPartitionedCall:
outputs['num_boxes'] tensor_info:
dtype: DT_INT32
shape: (-)
name: StatefulPartitionedCall:
outputs['scores'] tensor_info:
dtype: DT_FLOAT
shape: (-, )
name: StatefulPartitionedCall:
Method name is: tensorflow/serving/predict

这个是model/detector模型的输出;

参考

1. tensorflow1.x;

2. tf_saved_model;

【tensorflow-v2.0】如何查看模型的输入输出流的属性的更多相关文章

  1. 使用TensorFlow v2.0构建卷积神经网络

    使用TensorFlow v2.0构建卷积神经网络. 这个例子使用低级方法来更好地理解构建卷积神经网络和训练过程背后的所有机制. CNN 概述 MNIST 数据集概述 此示例使用手写数字的MNIST数 ...

  2. TensorFlow v2.0实现Word2Vec算法

    使用TensorFlow v2.0实现Word2Vec算法计算单词的向量表示,这个例子是使用一小部分维基百科文章来训练的. 更多信息请查看论文: Mikolov, Tomas et al. " ...

  3. 使用TensorFlow v2.0构建多层感知器

    使用TensorFlow v2.0构建一个两层隐藏层完全连接的神经网络(多层感知器). 这个例子使用低级方法来更好地理解构建神经网络和训练过程背后的所有机制. 神经网络概述 MNIST 数据集概述 此 ...

  4. TensorFlow v2.0实现逻辑斯谛回归

    使用TensorFlow v2.0实现逻辑斯谛回归 此示例使用简单方法来更好地理解训练过程背后的所有机制 MNIST数据集概览 此示例使用MNIST手写数字.该数据集包含60,000个用于训练的样本和 ...

  5. TensorFlow v2.0的基本张量操作

    使用TensorFlow v2.0的基本张量操作 from __future__ import print_function import tensorflow as tf # 定义张量常量 a = ...

  6. tensorflow 1.0 学习:模型的保存与恢复(Saver)

    将训练好的模型参数保存起来,以便以后进行验证或测试,这是我们经常要做的事情.tf里面提供模型保存的是tf.train.Saver()模块. 模型保存,先要创建一个Saver对象:如 saver=tf. ...

  7. tensorflow 1.0 学习:模型的保存与恢复

    将训练好的模型参数保存起来,以便以后进行验证或测试,这是我们经常要做的事情.tf里面提供模型保存的是tf.train.Saver()模块. 模型保存,先要创建一个Saver对象:如 saver=tf. ...

  8. TensorFlow 2.0高效开发指南

    Effective TensorFlow 2.0 为使TensorFLow用户更高效,TensorFlow 2.0中进行了多出更改.TensorFlow 2.0删除了篇冗余API,使API更加一致(统 ...

  9. 在Anaconda3环境下安装并切换 Tensorflow 2.0 环境

    背景 Anaconda切换各种环境非常方便,现在我们就来介绍一下如何使用anaconda安装tensorflow环境. anaconda v3.5 from 清华镜像站 tensorflow v2.0 ...

随机推荐

  1. C++ - STL - map的基础操作

    STL - map常用方法 map简述 map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,其作用类似于 ...

  2. nodejs中判断请求来自PC端还是移动端

    获取req.headers["user-agent"]: var deviceAgent = req.headers["user-agent"].toLower ...

  3. DataNode 工作机制

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_35641192/article/d ...

  4. django-支付宝支付

    安装python-alipay-sdk pip install python-alipay-sdk --upgrade 配置 视图函数orders/views.py # 订单支付 # /order/p ...

  5. How would you differentiate JDK, JRE, JVM, and JIT?

    Q5. How would you differentiate JDK, JRE, JVM, and JIT?A5. There is no better way to get the big pic ...

  6. UNICODE和UCS

    Unicode是国际组织制定的可以容纳世界上所有文字和符号的字符编码方案.目前的Unicode字符分为17组编排,0x0000 至 0xFFFF,每组称为平面(Plane),而每平面拥有65536个码 ...

  7. [Javascript] ES6 Class Constructors and the Super Keyword

    When the ES6 class shipped back in 2015, a number of additional keywords came with it. Two of these ...

  8. LeetCode 934. Shortest Bridge

    原题链接在这里:https://leetcode.com/problems/shortest-bridge/ 题目: In a given 2D binary array A, there are t ...

  9. ABP 基本操作

    基本信息: 官网:https://aspnetboilerplate.com api:https://aspnetboilerplate.com/Pages/Documents/Articles-Tu ...

  10. 17-网页,网站,微信公众号基础入门(使用Adobe Dreamweaver CS6 制作网页/网站)

    https://www.cnblogs.com/yangfengwu/p/11351182.html https://www.cnblogs.com/yangfengwu/p/11200767.htm ...