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 [].
whoyouwith91 opened this issue · 4 comments
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?
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.
I'm currently using tf 1.3.0.
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
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