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.
# =======