deepdream_visualization error: invalid reduction dimension
See original GitHub issueWhen I call the deepdream_visualization function in the following way for MNIST classification,
random_representation = mnist_data.test.next_batch(1)
ran_x = preprocess_batch(random_representation[0], mean, std)
ran_y = random_representation[1]
feed_dict = {x: ran_x, y: ran_y, is_training: False, keep_probability: 1}
deep_dream = True
if deep_dream:
layer = 'Conv/convolution'
start = time.time()
deepdream_visualization(graph_or_path=tf.get_default_graph(), value_feed_dict=feed_dict, layer=layer,
classes=[1, 2, 3, 4, 5, 6, 7, 8, 9],
input_tensor=None,
path_logdir="C:/Users/bucpau/PycharmProjects/Academy/Logs/",
path_outdir="C:/Users/bucpau/PycharmProjects/Academy/Visualization/")
start = time.time() - start
print("Total time for deconvolution visualization: {} Success: {}".format(start, is_success))
I get an error:
Traceback (most recent call last): File "C:/Users/bucpau/PycharmProjects/Academy/CNN_MNIST.py", line 156, in <module> main() File "C:/Users/bucpau/PycharmProjects/Academy/CNN_MNIST.py", line 153, in main visualize_layers(test_dict) File "C:/Users/bucpau/PycharmProjects/Academy/CNN_MNIST.py", line 85, in visualize_layers path_outdir="C:/Users/bucpau/PycharmProjects/Academy/Visualization/") File "C:\ProgramData\Anaconda3\lib\site-packages\tf_cnnvis-1.0.0-py3.6.egg\tf_cnnvis\tf_cnnvis.py", line 393, in deepdream_visualization File "C:\ProgramData\Anaconda3\lib\site-packages\tf_cnnvis-1.0.0-py3.6.egg\tf_cnnvis\tf_cnnvis.py", line 138, in _get_visualization File "C:\ProgramData\Anaconda3\lib\site-packages\tf_cnnvis-1.0.0-py3.6.egg\tf_cnnvis\tf_cnnvis.py", line 264, in _visualization_by_layer_name File "C:\ProgramData\Anaconda3\lib\site-packages\tf_cnnvis-1.0.0-py3.6.egg\tf_cnnvis\tf_cnnvis.py", line 317, in _deepdream File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\math_ops.py", line 1382, in reduce_mean name=name) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 1364, in _mean keep_dims=keep_dims, name=name) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op op_def=op_def) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 2632, in create_op set_shapes_for_outputs(ret) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1911, in set_shapes_for_outputs shapes = shape_func(op) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1861, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 595, in call_cpp_shape_fn require_shape_fn) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 659, in _call_cpp_shape_fn_impl raise ValueError(err.message) ValueError: Invalid reduction dimension 2 for input with 2 dimensions. for 'Mean_1' (op: 'Mean') with input shapes: [?,784], [3] and with computed input tensors: input[1] = <1 2 3>. .
Any ideas on what is happening here? Is it a bug or am I using the function incorrectly? The activation visualization works, but the deconvolution does not with the input feed_dict. The only addition to this function call in comparison to the activation visualization are the parameters classes and layer. Am I setting them correctly?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)

Top Related StackOverflow Question
Hii @pabucur,
We found the root cause of the error.
Numpy < 1.12caused this issue since there was a change in the arguments that go intonp.rollstarting fromnumpy==1.12. But now we have updatedtf_cnnvisto allow for backward compatibility with numpy.Now
git pull tf_cnnvisand setup should resolve this issue. Thanks for taking the time to debug and point out this issue.Thank You.
@BhagyeshVikani I posted the code into a new Python file, without changing anything. It does not work for me, the error is the same. I am on Windows 7 and using Tensorflow with GPU support, version 1.3.0-rc1.