GeorgeSeif / Semantic-Segmentation-Suite

Semantic Segmentation Suite in TensorFlow. Implement, train, and test new Semantic Segmentation models easily!
2.51k stars 880 forks source link

there is wrong when transfer ckpt to pb model #221

Closed cena001plus closed 5 years ago

cena001plus commented 5 years ago

i want to use this model on android platform, so transfer ckpt model to pb model, but just one op in the graph. and the pb model is null , just 70Byte size.

the transfer code is blow:

``import tensorflow as tf
from tensorflow.python.framework import graph_util
from tensorflow.python.platform import gfile
def freeze_graph(ckpt, output_graph):
    output_node_names = "logits/biases"
    saver = tf.train.import_meta_graph(ckpt+'.meta', clear_devices=False)
    graph = tf.get_default_graph()
    input_graph_def = graph.as_graph_def()

    with tf.Session() as sess:
        saver.restore(sess, ckpt)
        output_graph_def = graph_util.convert_variables_to_constants(
          sess=sess,
          input_graph_def=input_graph_def,
          output_node_names=output_node_names.split(',')
        )
        with tf.gfile.GFile(output_graph, 'wb') as fw:
            fw.write(output_graph_def.SerializeToString())
            print ('{} ops in the final graph.'.format(len(output_graph_def.node)))

ckpt = './04/model.ckpt'
pb = './04/model.pb'

if __name__ == '__main__':
    freeze_graph(ckpt, pb)

the result is blow


Instructions for updating:
Use tf.compat.v1.graph_util.extract_sub_graph
1 ops in the final graph.
cena001plus commented 5 years ago

solved! https://github.com/GeorgeSeif/Semantic-Segmentation-Suite/issues/105