New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tf.unravel_index (Was: tf.argmin across all dimensions) #2075
Comments
I think it'd be better to handle this the way numpy does it, with Cc @aselle since |
where is tf.unravel_index in the document? I cannot find it. |
Not sure which document you mean, but |
Yeah. I know np.unravel_index. but can np.unravel_index be used to build the graph?
|
Someone would have to write a TensorFlow version of |
Here's a sketch of a possible Python implementation using import tensorflow as tf
def unravel_index(indices, shape):
with tf.name_scope('unravel_index'):
indices = tf.expand_dims(indices, 0)
shape = tf.expand_dims(shape, 1)
strides = tf.cumprod(shape, reverse=True)
strides_shifted = tf.cumprod(shape, exclusive=True, reverse=True)
return (indices // strides_shifted) % strides
s = tf.Session()
out = unravel_index([22, 41, 37], (7, 6))
print(s.run(out))
# ==> [[3 6 6]
# [4 5 1]] |
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks! |
@ibab The last line in the function |
I think |
In fact, the implementation must depend on the parity of the rank of the shape. Following modification works for both cases and runs smoothly on cpu and gpu.
|
Hi,
tf.argmin only works in one dimension.
Let's say I have a picture which is a 2x2 array of pixels (each pixels is a 3 value array) and I want to know which pixel is closest to a certain color. In that case I have to reshape the 2x2 array to a 1-D array then get the min index, then find out that index to what 2x2 array position corresponds.
Couldn't I just as tensorflow to give me the index in the 2x2 array. For instance [1,15]?
I really don't understand the reason for having to translate between lineal index and array location all the time.
Thanks.
The text was updated successfully, but these errors were encountered: