infocusp / tf_cnnvis

CNN visualization tool in TensorFlow
MIT License
781 stars 208 forks source link

Fail to create frozen graph. #49

Closed ZhengLyuFelix closed 6 years ago

ZhengLyuFelix commented 6 years ago

I'm trying to do visualization on custom pre trained model and I met with the problem after I tried to create frozen graph like this:

od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
    serialized_graph = fid.read()
    od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')

then I tried to do the activation visualization:

layers = ['r', 'p', 'c']

start = time.time()
temp = tf.get_default_graph()
print(temp)
X = tf.placeholder(np.uint8, shape = [1, 370, 1224, 3])
# with detection_graph.as_default():
# with sess_graph_path = None, the default Session will be used for visualization.\
is_success = activation_visualization(sess_graph_path = tf.get_default_graph(), value_feed_dict = {X : im}, 
                                          layers=layers, path_logdir=os.path.join("Log","Kitti"), 
                                          path_outdir=os.path.join("Output","Kitti"))
start = time.time() - start
print("Total Time = %f" % (start))

Then I got the error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-82e3351f0452> in <module>()
     10 is_success = activation_visualization(sess_graph_path = tf.get_default_graph(), value_feed_dict = {X : im}, 
     11                                           layers=layers, path_logdir=os.path.join("Log","Kitti"),
---> 12                                           path_outdir=os.path.join("Output","Kitti"))
     13 start = time.time() - start
     14 print("Total Time = %f" % (start))

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tf_cnnvis-1.0.0-py2.7.egg/tf_cnnvis/tf_cnnvis.pyc in activation_visualization(sess_graph_path, value_feed_dict, input_tensor, layers, path_logdir, path_outdir)
    404 def activation_visualization(sess_graph_path, value_feed_dict, input_tensor = None,  layers = 'r', path_logdir = './Log', path_outdir = "./Output"):
    405     is_success = _get_visualization(sess_graph_path, value_feed_dict, input_tensor = input_tensor, layers = layers, method = "act",
--> 406         path_logdir = path_logdir, path_outdir = path_outdir)
    407     return is_success
    408 def deconv_visualization(sess_graph_path, value_feed_dict, input_tensor = None,  layers = 'r', path_logdir = './Log', path_outdir = "./Output"):

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tf_cnnvis-1.0.0-py2.7.egg/tf_cnnvis/tf_cnnvis.pyc in _get_visualization(sess_graph_path, value_feed_dict, input_tensor, layers, path_logdir, path_outdir, method)
    129     # convert all inplicit and explicit sess input cases to a PATH
    130     if isinstance(sess_graph_path, tf.Graph):
--> 131         PATH = _save_model(sess_graph_path)
    132     elif isinstance(sess_graph_path, tf.Session):
    133         PATH = _save_model(sess_graph_path)

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tf_cnnvis-1.0.0-py2.7.egg/tf_cnnvis/tf_cnnvis.pyc in _save_model(graph_or_sess)
     63         for op in ops:
     64             if 'variable' in op.type.lower():
---> 65                 raise ValueError('Please input a frozen graph (no variables). Or pass in the session object.')
     66 
     67         with graph_or_sess.as_default():

ValueError: Please input a frozen graph (no variables). Or pass in the session object.

I'm not sure if I wrongly created the frozen graph. Please help me if I did it wrongly. Many thanks!

BhagyeshVikani commented 6 years ago

Hi @ZhengLyuFelix Try using the session directly as mentioned in the error above

Please input a frozen graph (no variables). Or pass in the session object. Since your model has variables present.

Also, there is no need to add an external standalone placeholder (X from the example above). It'll cause errors. Just pass in the input to your model, the library functions will detect the input node automatically.

falaktheoptimist commented 6 years ago

Closing this for lack of activity. Reopen if needed.