【tensorflow-v2.0】如何查看模型的输入输出流的属性

 操作过程:

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 83 trainable variables: conv1/kernel:0, conv1_bn/gamma:0, conv1_bn/beta:0, conv_dw_1/depthwise_kernel:0, conv_dw_1_bn/gamma:0,...
MobileNet also has 54 non-trainable variables: conv1_bn/moving_mean:0, conv1_bn/moving_variance:0, conv_dw_1_bn/moving_mean:0, ...

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

Traceback (most recent call last):
  File "inspect_saved_model.py", line 59, 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: (-1, -1, -1, -1)
        name: serving_default_images:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['boxes'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100, 4)
        name: StatefulPartitionedCall:0
    outputs['num_boxes'] tensor_info:
        dtype: DT_INT32
        shape: (-1)
        name: StatefulPartitionedCall:1
    outputs['scores'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 100)
        name: StatefulPartitionedCall:2
  Method name is: tensorflow/serving/predict
复制代码

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

 参考

1. tensorflow1.x;

2. tf_saved_model;

posted on   鹅要长大  阅读(1822)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2018-11-08 【leetcode】20-ValidParentheses

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示