Skip to content
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

ValueError: Tried to convert 'indices' to a tensor and failed. Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted []. #3

Open
whoyouwith91 opened this issue Nov 1, 2017 · 4 comments

Comments

@whoyouwith91
Copy link

def linearND(input_, output_size, scope, init_bias=0.0):
shape = input_.get_shape().as_list()
ndim = len(shape)
#print(ndim)
stddev = min(1.0 / math.sqrt(shape[-1]), 0.1)
with tf.variable_scope(scope):
W = tf.get_variable("Matrix", [shape[-1], output_size], tf.float32, tf.random_normal_initializer(stddev=stddev))
X_shape = tf.gather(tf.shape(input_), range(ndim-1))
target_shape = tf.concat(0, [X_shape, [output_size]])
exp_input = tf.reshape(input_, [-1, shape[-1]])
if init_bias is None:
res = tf.matmul(exp_input, W)
else:
with tf.variable_scope(scope):
b = tf.get_variable("bias", [output_size], initializer=tf.constant_initializer(init_bias))
res = tf.matmul(exp_input, W) + b
res = tf.reshape(res, target_shape)
res.set_shape(shape[:-1] + [output_size])
return res

It seems that the line "X_shape = tf.gather(tf.shape(input_), range(ndim-1))" can't work. Could you help me figure it out?

@wengong-jin
Copy link
Collaborator

This is very surprising. Which tensorflow version are you using? I know there's discrepancy between tf.0.12.0 and tf 1.0+. We only tested our code on v0.12.0.

@whoyouwith91
Copy link
Author

I'm currently using tf 1.3.0.

@whoyouwith91
Copy link
Author

Hi, I have fixed some minor discrepancies between the v0.12.0 and v1.3.0. However, it brings a new error: F tensorflow/core/framework/tensor_shape.cc:243] Check failed: ndims_byte() < MaxDimensions() (unsigned char value 254 vs. 254)Too many dimensions in tensor
Abort trap: 6

@connorcoley
Copy link

In case anyone else runs into this problem, there is an issue with tf.gather(tf.shape(input_), range(ndim-1)) using python 3 because range(ndim-1) cannot be automatically converted to a tensor. Replacing it with list(range(ndim-1)) to explicitly cast it to a list resolves that specific error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants