Closed pazadeh closed 6 years ago
You need not add an external standalone placeholder for the image. Just pass in the input image where the input node is present in your model (input_loc in the example you shared above). That should fix the problem.
Thanks. That solved the issue.
Hi, I am trying to use your code to visualize the max activation of different layers in my deep neural network but I keep receiving the following error which I assume has something to do with the way the names of the layers are defined. the error:
Traceback (most recent call last):
File "", line 1, in
runfile('/media/asgharpn/daten2017-03/Bone_Machine_learning/ML_temp/Deeploc_test/Visualization_max_activation_00.py', wdir='/media/asgharpn/daten2017-03/Bone_Machine_learning/ML_temp/Deeploc_test')
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile execfile(filename, namespace)
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile builtins.execfile(filename, *where)
File "/media/asgharpn/daten2017-03/Bone_Machine_learning/ML_temp/Deeploc_test/Visualization_max_activation_00.py", line 164, in
path_logdir='./Log', path_outdir='./Output')
File "build/bdist.linux-x86_64/egg/tf_cnnvis/tf_cnnvis.py", line 410, in deconv_visualization path_logdir = path_logdir, path_outdir = path_outdir)
File "build/bdist.linux-x86_64/egg/tf_cnnvis/tf_cnnvis.py", line 166, in _get_visualization is_success = _visualization_by_layer_name(g, value_feed_dict, input_tensor, layer, method, path_logdir, path_outdir)
File "build/bdist.linux-x86_64/egg/tf_cnnvis/tf_cnnvis.py", line 270, in _visualization_by_layer_name parsed_tensors = parse_tensors_dict(graph, layer_name, value_feed_dict)
File "build/bdist.linux-x86_64/egg/tf_cnnvis/utils.py", line 79, in parse_tensors_dict tmp = get_tensor(graph = g, name = key_op.name)
AttributeError: 'str' object has no attribute 'name'
Here is the architecure of my trained network with 13 layers (8 convolutional, 3 relu and 2 fully connected layers):
n_feat_c1 = 8 n_feat_c2 = 8 n_feat_c3 = 16 n_feat_c4 = 16 n_feat_c5 = 32 n_feat_c6 = 32 n_feat_c7 = 64 n_feat_c8 = 64 n_feat_fc1= 128 n_feat_fc2= 128 numClasses = 4
def DeepLocModel(input_images,is_training):
and finally here is the code I use to visualize the activations using tf_cnnviz:
sess = tf.Session() sess.run(tf.global_variables_initializer(),{is_training:False})
load model checkpoint
saver = tf.train.Saver(tf.global_variables()) saver.restore(sess, locNetCkpt)
Loading labels from test data set
dataBaseDir = '/media/asgharpn/daten2017-03/Bone_Machine_learning/Learning_dataset/projected_augmented_not_squared_yz_test/' trainHdf5 = dataBaseDir+'bone_projected_valid_set.hdf5' f = h5py.File(trainHdf5,'r') labels = f['Index1'] dset = f['data1']
cropSize = 733 batchSize = dset.shape[0]-1 stretchLow = 0.1 # stretch channels lower percentile stretchHigh = 99.9 # stretch channels upper percentile
imSize_x = 733
imSize_z = 161 numClasses = 4 numChan = 1
data = dataClass.Data(trainHdf5,['data','Index'],batchSize) batch = data.getBatch() loc = tf.Graph() with loc.as_default(): loc_saver = tf.train.import_meta_graph(locNetCkpt+'.meta') locSession = tf.Session(graph=loc) loc_saver.restore(locSession, locNetCkpt)
pred_loc = loc.get_tensor_by_name(u'softmax:0') input_loc = loc.get_tensor_by_name(u'input:0') is_training_loc = loc.get_tensor_by_name(u'is_training:0') processedBatch=procIm.preProcessImages(batch['data'], imSize_x,imSize_z,cropSize,numChan, rescale=False,stretch=False, means=None,stds=None, stretchLow=stretchLow,stretchHigh=stretchHigh, jitter=False,randTransform=False)
images = processedBatch[10][:] is_training_loc = loc.get_tensor_by_name(u'is_training:0') input_loc = loc.get_tensor_by_name(u'input:0') feed_dict={input_loc: images, is_training_loc: False}
deconv visualization
layers = ["c"] totaltime = 0 x = tf.placeholder(tf.float32, [None, 118013]) y = tf.placeholder(tf.float32, [None, 4]) keep_prob = tf.placeholder(tf.float32)
x_image = tf.reshape(x, [-1, 733, 161, 1]) start = time.time()
feeddict = {x:batch['data'][1:2], y: batch['Index'][1:2], keep_prob: 1.0} is_success = deconv_visualization(sess_graph_path = sess, value_feed_dict = batch, input_tensor=x_image, layers=layers, path_logdir='./Log', path_outdir='./Output') start = time.time() - start print("Total Time = %f" % (start))
sess.close()
Could you please help me with this error?