mrharicot / monodepth

Unsupervised single image depth prediction with CNNs
Other
2.22k stars 631 forks source link

How to freeze model? #181

Closed gi097 closed 6 years ago

gi097 commented 6 years ago

Hello,

I downloaded your pretrained cityscapes model. The files contained in there are:

I did like to freeze the graph to a frozen .pb file. So I am using this script to load and freeze the model:

import tensorflow as tf

meta_path = 'model_cityscapes.meta' 
output_node_names = ['output:0']

with tf.Session() as sess:

    # Restore the graph
    saver = tf.train.import_meta_graph(meta_path)

    # Load weights
    saver.restore(sess,tf.train.latest_checkpoint('.'))

    # Freeze the graph
    frozen_graph_def = tf.graph_util.convert_variables_to_constants(
        sess,
        sess.graph_def,
        output_node_names)

    # Save the frozen graph
    with open('output_graph.pb', 'wb') as f:
      f.write(frozen_graph_def.SerializeToString())

However, since your provided files do not include any checkpoint, the following line raises an error: tf.train.latest_checkpoint('.'), it returns None.

Could you explain how to correctly freeze this model?

gi097 commented 6 years ago

I was able to load the graph using:

import tensorflow as tf

meta_path = 'model_cityscapes.meta'
output_node_names = ['output:0']

with tf.Session() as sess:

    # Restore the graph
    saver = tf.train.import_meta_graph(meta_path, clear_devices=True)

    graph = tf.get_default_graph()
    input_graph_def = graph.as_graph_def()
    sess = tf.Session()
    saver.restore(sess, "model_cityscapes")
gi097 commented 6 years ago

I have trouble finding the output node name of this model. Do you know the name?

Adarine99 commented 6 years ago

I have trouble finding the output node name of this model. Do you know the name?

Hi,I got this problem too.Do you know the output_node now? Thanks