In Tensorflow, how to unravel the flattened indices obtained by tf.nn.max_pool_with_argmax?

匿名 (未验证) 提交于 2019-12-03 03:00:02

问题:

I meet a problem: After I use the tf.nn.max_pool_with_argmax, I obtain the indices i.e. argmax: A Tensor of type Targmax. 4-D. The flattened indices of the max values chosen for each output.

How to unravel the flattened indices back to the coordinates list in Tensorflow?

Thank you very much.

回答1:

I had the same problem today and I ended up with this solution:

def unravel_argmax(argmax, shape):     output_list = []     output_list.append(argmax // (shape[2] * shape[3]))     output_list.append(argmax % (shape[2] * shape[3]) // shape[3])     return tf.pack(output_list) 

Here is a usage example in a ipython notebook (I use it to forward the pooling argmax positions to my unpooling method)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!