Tensorflow 'IndexedSlices' object has no attribute 'get_shape' during backprop through while_loop -


i'm experimenting writing own dynamic_rnn() function. i'm getting following error when initialising model:

attributeerror: 'indexedslices' object has no attribute 'get_shape' 

it's calculating gradients. here full stack trace (nb. happens if remove gradient clip - moves optimizer).

attributeerror                            traceback (most recent call last) <ipython-input-8-c4ed7a228363> in <module>() ----> 1 model = model(args)  <ipython-input-5-2ab152ab1152> in __init__(self, args, infer)      58       59         tvars = tf.trainable_variables() ---> 60         grads, _ = tf.clip_by_global_norm(tf.gradients(self.cost, tvars),      61                 args.grad_clip)      62         optimizer = tf.train.adamoptimizer(self.lr) # tf.train.gradientdescentoptimizer(self.lr) #  /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients.pyc in gradients(ys, xs, grad_ys, name, colocate_gradients_with_ops, gate_gradients, aggregation_method)     479                 # pylint: enable=protected-access     480               else: --> 481                 in_grads = _aslist(grad_fn(op, *out_grads))     482               _verifygeneratedgradients(in_grads, op)     483               if gate_gradients , len(  /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_grad.pyc in _entergrad(op, grad)     184   if op.get_attr("is_constant"):     185     # add gradient accumulator each loop invariant. --> 186     result = grad_ctxt.addbackpropaccumulator(grad)     187   else:     188     result = exit(grad)  /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.pyc in addbackpropaccumulator(self, value)    1430     """    1431     self.exit() -> 1432     shape = value.get_shape()    1433     if not shape.is_fully_defined():    1434       shape = none  attributeerror: 'indexedslices' object has no attribute 'get_shape' 

i've identified problem in while_loop. if add backprop=false argument while_loop function fine. below relevant code.

inputs = array_ops.transpose(self.input_data, [1, 0]) input_shape = array_ops.shape(inputs) (time_steps, batch_size) = array_ops.unpack(input_shape, 2) time = array_ops.constant(0, dtype=dtypes.int32, name="time") state = self.initial_state  # tensorarrays base_name = scope  output_ta = tensor_array_ops.tensorarray(     dtype=dtypes.float32, size=time_steps,     tensor_array_name=base_name + "output")  input_ta = tensor_array_ops.tensorarray(     dtype=inputs.dtype, size=time_steps,     tensor_array_name=base_name + "input")  input_ta = input_ta.unpack(inputs)  # step function def _take_step(cur_time, output_ta_t, cur_state):     inps = input_ta.read(cur_time)     step_inps = tf.nn.embedding_lookup(embedding, inps)     step_inps = tf.reshape(step_inps,[-1,self.input_embedding_size])     output, new_state = self.cell((step_inps, attention), cur_state)     output_ta_t = output_ta_t.write(cur_time, output)     variable_scope.get_variable_scope().reuse_variables()     return (cur_time + 1, output_ta_t, new_state)  # tensor while_loop final_loop_vars = control_flow_ops.while_loop(       cond=lambda t, *_: t < time_steps,       body=_take_step,       loop_vars=(time, output_ta, state),       parallel_iterations=none,       swap_memory=false) 

as possible i've tried copy code dynamic_rnn(). though have simplified bit particular use case.

i'm not sure part of code creating indexedslices object. i'm having trouble working out start debugging.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -