infocusp / tf_cnnvis

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

No output to log or output directory #44

Closed afeltham closed 6 years ago

afeltham commented 6 years ago

Hello, I'm rather new to all this so forgive me if this is a daft question. However, i just can't get the examples to work with my data. I've basically followed the "Training" section of https://www.tensorflow.org/tutorials/image_retraining and have had some good results from the resulting model. However, i want to visualise them and your library seems perfect for the job!

What am i doing wrong in the code below? I get no errors and 'is_success' is True so it appears to have worked?

import os
import sys
import time
import copy
import h5py
import numpy as np

from tf_cnnvis import *

import tensorflow as tf
from scipy.misc import imread, imresize

t_input = tf.placeholder(np.float32, name='Placeholder') # define the input tensor

graph = tf.Graph()
graph_def = tf.GraphDef()

with open('./path/to/my/graph.pb', "rb") as f:
  graph_def.ParseFromString(f.read())

with graph.as_default():
  tf.import_graph_def(graph_def)

# reading sample image
im = np.expand_dims(imread(os.path.join("./", "FILENAME.JPG")), axis = 0)

tensor_names = [t.name for op in graph.get_operations() for t in op.values()]
print(tensor_names[0])
print(tensor_names[len(tensor_names) - 1])

start = time.time()
# api call

is_success  = activation_visualization(
                                            sess_graph_path=tf.get_default_graph(),
                                            value_feed_dict = {t_input : im}, 
                                            input_tensor=tensor_names[len(tensor_names) - 1],
                                            layers=[ 'r', 'p', 'c'], 
                                            path_outdir="./output",
                                            path_logdir="./log"
                                         )
start = time.time() - start
print("Total Time = %f" % (start))
print(is_success)

The main things i don't seem to understand is the value_feed_dict, the input_tensor and the t_input / im variables.

I'm sure i'm doing something daft but would be trivial for someone in the know to spot what is wrong.

Thank you!

falaktheoptimist commented 6 years ago

You do not need to add an extra placeholder for the input. The one which your network has for taking in the input image would work. In the feed_dict, you need to pass in the input image to the placeholder in your network which takes in the input image, not into the extra one you added (re iterating - there is no need for that extra placeholder).
Hope this helps. Let us know if you need any further help with the debugging.

afeltham commented 6 years ago

HI @falaktheoptimist thanks for the reply... sorry for being basic... but could you put that last paragraph into a code example? As mentioned before... i'm a bit new to all this.... Thanks!

falaktheoptimist commented 6 years ago

There are 3 example notebooks in the repo ( https://github.com/InFoCusp/tf_cnnvis/tree/master/examples ), which I think would help you understand this idea very clearly. Please have a look and if you have any questions there, I would be happy to clarify.

BhagyeshVikani commented 6 years ago

@afeltham Closing this issue for now. Re-open if you are still facing the issue.