How to use tf.nn.max_pool_with_argmax correctly
<p>currently I play a little bit around with tensorflow to create a better understanding of machine learning an tensorflow itself. Therefore I want to visualize the methods (as much as possible) of tensorflow. To visualize max_pool I loaded an image and perform the method. After that I displayed both: input and output image.</p>

<pre class="lang-py prettyprint-override"><code>import tensorflow as tf
import cv2
import numpy as np

import matplotlib.pyplot as plt

image = cv2.imread('lena.png')
image_tensor = tf.expand_dims(tf.Variable(image, dtype=tf.float32), 0)

#output, argmax = tf.nn.max_pool_with_argmax(image_tensor, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')
output = tf.nn.max_pool(image_tensor, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')

init = tf.initialize_all_variables()
session = tf.Session()
session.run(init)

output = session.run(output)

session.close()

image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
plt.figure()
plt.imshow(image)
plt.show()

output = cv2.cvtColor(output[0], cv2.COLOR_RGB2BGR)
plt.figure()
plt.imshow(255-output)
plt.show() 
</code></pre>

<p>Everything works fine and I get this output (as expected)</p>

<p><a href="http://i.stack.imgur.com/FFoKmm.png" rel="nofollow"><img src="http://i.stack.imgur.com/FFoKmm.png" alt="image (input)"></a>
<a href="http://i.stack.imgur.com/YZhogm.png" rel="nofollow"><img src="http://i.stack.imgur.com/YZhogm.png" alt="enter image description here"></a></p>

<p>Now I wanted to test the method <code>tf.nn.max_pool_with_argmax</code> to get the argmax of the pooling operations. But if I uncomment the line </p>

<p><code>output, argmax = tf.nn.max_pool_with_argmax(image_tensor, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1')
</code></p>

<p>Python crashes with </p>

<blockquote>
  <p>tensorflow.python.framework.errors.InvalidArgumentError: No OpKernel was registered to support Op 'MaxPoolWithArgmax' with these attrs
       [[Node: pool1 = MaxPoolWithArgmaxT=DT_FLOAT, Targmax=DT_INT64, ksize=[1, 2, 2, 1], padding="SAME", strides=[1, 2, 2, 1]]]</p>
</blockquote>

<p>I don't have an idea which argument is wrong because every argument should be correct (<a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/nn.html#max_pool_with_argmax" rel="nofollow">tensorflow docs</a>) ...</p>

<p>Does anyone know what went wrong?</p>

<p>From a look at <a href="https://github.com/tensorflow/tensorflow/blob/bc64f05d4090262025a95438b42a54bfdc5bcc80/tensorflow/core/kernels/maxpooling_op.cc#L672" rel="nofollow">the implementation</a>, it appears that the <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/nn.html#max_pool_with_argmax" rel="nofollow"><code>tf.nn.max_pool_with_argmax()</code></a> is only implemented for GPU. If you are running the CPU-only build of TensorFlow, then you would get an error of the form <code>"No OpKernel was registered to support Op 'MaxPoolWithArgmax' with these attrs ..."</code>.</p>

<p>(This seems like a place where the documentation and the error message could be improved.)</p>

python tensorflow