操作过程:

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. [GXOI/GZOI2019]旅行者 (最短路)

    题意 给定一个有向图,其中一些顶点为关键点.求这些关键点两两之间最小距离. 题解 考试时没怎么想写了50分暴力走了.以为是什么强连通分量的解法,结果就是个最短路.直接从关键点跑一次最短路dis[0], ...

  2. PHP函数file_get_contents()使用 https 协议时报错:SSL operation failed

    场景: file_get_contents() 函数是用于将文件的内容读入到一个字符串中,是读取文件内容常用的函数之一. 但是有时在服务器上使用file_get_contents() 函数请求http ...

  3. Xamarin.Forms一些常见问题

    安装 1.查看Xaramin.Forms的版本 在vs项目中查看引用的包(Xamarin.Forms)的版本,或者直接进文件夹看 C:\Microsoft\Xamarin\NuGet\xamarin. ...

  4. ABP 04 用户的创建

    有这样一个问题,我忘记了密码,查了一下数据那张表,是加密了的,然后就有了这篇文章了. 往后台传的时候,还是传的明文. 请求的地址:/api/services/app/User/Create 用户还是挺 ...

  5. Comet OJ - Contest #15 题解

    传送门 \(A\) 咕咕 const int N=1005; int a[N],n,T; int main(){ for(scanf("%d",&T);T;--T){ sc ...

  6. Zookeeper循环注册监听器

    Zookeeper中的监听器只执行一次,需要在watcher类中重写process方法,以达到重复注册监听器的效果 /** * 连接zk服务器 * */ public static void conn ...

  7. 在Eclipse打开css文件时,会自动调用文本编辑器打开,而不是在Eclipse中打开

    问题描述 在Eclipse中打开css文件时候,如下图,使用系统自带的文本编辑器打开 解决方案 点击Window下的Preference,找到File Associations,然后点击Add,将cs ...

  8. 向量召回 vearch

    开源向量召回工具 https://github.com/vearch/vearch 架构

  9. What is the difference between UNION and UNION ALL?

    What is the difference between UNION and UNION ALL? UNION removes duplicate records (where all colum ...

  10. Guava集合工具

    JDK提供了一系列集合类,如下所示,极大的方便了开发工作,并针对这些类提供了一个工具类java.util.Collections,Guava在此基础上添加了一些常用工具类方法,相比于java.util ...