Tensorflow 模型文件格式转换

Tensorflow模型的graph结构可以保存为.pb文件或者.pbtxt文件,或者.meta文件,其中只有.pbtxt文件是可读的

网上大牛们训练好的网络,往往会利用我上篇博客讲的方法,将模型保存为一个统一的.pb文件,这个文件中不止保存着模型网络的结构和变量名,

还保存了所有变量的值,如果我们想利用别人训练好的模型对自己的数据进行测试,往往要对这个模型做一些修改,

参见我的下一篇博客《Tensorflow之迁移学习》,

这时我们经常需要知道原有模型里面的一些张量名称,但是.pb文件和.meta文件都是不可读的,所有有必要对这两种文件进行格式转换。

①.meta文件

这种情况下,通常还需要其他几个checkpoint文件,checkpoint ,model.cpkt.index,model.cpkt.data 等,可以使用tensofrflow安装目录下的 /home/zhaixingzhe/tensorflow/tensorflow/python/tools/inspect_checkpoint.py 文件打印输出模型中所有张量(tensor)和操作(op)的名称

下面是inspect_checkpoint.py的全部代码:

# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =======
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值