question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

deepdream_visualization error: invalid reduction dimension

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
BhagyeshVikanicommented, Aug 10, 2017

Hii @pabucur,

We found the root cause of the error. Numpy < 1.12 caused this issue since there was a change in the arguments that go into np.roll starting from numpy==1.12. But now we have updated tf_cnnvis to allow for backward compatibility with numpy.

Now git pull tf_cnnvis and setup should resolve this issue. Thanks for taking the time to debug and point out this issue.

Thank You.

0reactions
pabucurcommented, Aug 10, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Invalid reduction dimension 1 for input with 1 ...
The error you get is ValueError: Invalid reduction dimension 1 for input with 1 dimensions . This pretty much means that if you...
Read more >
Python – ValueError: Invalid reduction dimension 1 for input ...
The error you get is ValueError: Invalid reduction dimension 1 for input with 1 dimensions . This pretty much means that if you...
Read more >
model interpretation and data valuation for machine learning a ...
the data distribution; f0 denotes the classification error (%) of the ... values (blue dash) reduce the class prediction accuracy more effectively than ......
Read more >
Deep Representation Learning for Multimedia Data Analysis ...
used to reduce the spatial dimensions (width and height) of input data. However, the number of input and output feature maps does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found