balancap / SSD-Tensorflow

Single Shot MultiBox Detector in TensorFlow
4.11k stars 1.89k forks source link

How to transfer the .ckpt to .pb? #389

Open lucky-xu-1994 opened 4 years ago

lucky-xu-1994 commented 4 years ago

I have learned a lot to how transfer .ckpt to .pb, but it needs the input_tensor_name and output_node_names , in this project I can't find them, so how can I transfer the .ckpt to .pb? please help!

tkone2018 commented 3 years ago

@lucky-xu-1994 你好,你这个搞定了嘛?我发现找不到模型的输入输出节点

lucky-xu-1994 commented 3 years ago

@lucky-xu-1994 你好,你这个搞定了嘛?我发现找不到模型的输入输出节点

你把ckpt文件的输入输出节点打印出来,如果是这个工程文件的的话, 我找到的是六个特征图的输出节点,每个特征图输出一个分类和位置回归,例如:第一个特征图是“ssd_512_vgg/softmax/Softmax”(分类),"ssd_512_vgg/block4_box/Reshape"(位置回归),要是想得到最终的结果,需要将所有层的输出综合一起做非极大值抑制,具体可以参考工程文件中的notebooks/ssd_notebook.ipynb, 输入节点是一个队列输入,如果想要方便测试单张图片,可以在冻结模型时通过输入占位符进行冻结。

tkone2018 commented 3 years ago

可以加qq或微信吗?qq:843783062 微信:tk-conquer

tkone2018 commented 3 years ago

@lucky-xu-1994 然后我就很迷惑

lucky-xu-1994 commented 3 years ago

@lucky-xu-1994 然后我就很迷惑

你要打印的是节点名字,试试这个,找一下soft_max输出 from tensorflow.python import pywrap_tensorflow import tensorflow as tf import os model_dir = '/home/pb/' ckpt='/home/logs/model.ckpt-332005'

with tf.Session() as sess: saver = tf.train.import_meta_graph(ckpt +'.meta', clear_devices=True) graph_def = tf.get_default_graph().as_graph_def(add_shapes=True) node_list = [n.name for n in graph_def.node] result_file = os.path.join(model_dir,'result1.txt') with open(result_file,'w+') as f: for node in node_list:

print("node_name", node)

        f.write(node+'\n')

print('done')

tkone2018 commented 3 years ago
import tensorflow as tf
import os
model_dir = './out/'
ckpt='F:/SSD/SSD-Tensorflow/train_model/model.ckpt-750'
with tf.Session() as sess:
    saver = tf.train.import_meta_graph(ckpt +'.meta', clear_devices=True)
graph_def = tf.get_default_graph().as_graph_def(add_shapes=True)
node_list = [n.name for n in graph_def.node]
result_file = os.path.join(model_dir,'result1.txt')
with open(result_file,'w+') as f:
    for node in node_list:
         #print("node_name", node)
        f.write(node+'\n')
        print('done')

代码格式是这样的吧

lucky-xu-1994 commented 3 years ago

import tensorflow as tf import os model_dir = './out/' ckpt='F:/SSD/SSD-Tensorflow/train_model/model.ckpt-750' with tf.Session() as sess: saver = tf.train.import_meta_graph(ckpt +'.meta', clear_devices=True) graph_def = tf.get_default_graph().as_graph_def(add_shapes=True) node_list = [n.name for n in graph_def.node] result_file = os.path.join(model_dir,'result1.txt') with open(result_file,'w+') as f: for node in node_list:

print("node_name", node)

    f.write(node+'\n')
    print('done')

代码格式是这样的吧

你把session下面的代码都放在会话结构中,然后仔细看一下网络的定义,找一下softmax输出 具体你可以参照 https://blog.csdn.net/guyuealian/article/details/82218092 以及https://blog.csdn.net/zkgoup/article/details/105657577?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

tkone2018 commented 3 years ago

好的,谢谢

tkone2018 commented 3 years ago

你好,我又来麻烦你了,哈哈,我找到的是六个特征图的输出节点,每个特征图输出一个分类和位置回归,例如:第一个特征图是“ssd_512_vgg/softmax/Softmax”(分类),"ssd_512_vgg/block4_box/Reshape"(位置回归),要是想得到最终的结果,需要将所有层的输出综合一起做非极大值抑制,具体可以参考工程文件中的notebooks/ssd_notebook.ipynb, 输入节点是一个队列输入,如果想要方便测试单张图片,可以在冻结模型时通过输入占位符进行冻结。 根据你之前说的,我现在也是得到了输入输出节点,现在是我想弄成可以发布服务的那种,那模型的输出就得是做过后处理的,请问一下如果将所有层的输出综合一起做非极大值抑制,我看了下那个推理文件,这个好像是得到6个输出节点后再进行后处理