0

I'm trying to use slice a tensor object in my graph. Code is as follows:

        utt_inputs = []
        idx = tf.zeros(shape=(), dtype=tf.int32)
        def add_inputs(idx):
            utt_input = tf.slice(last_outputs, begin=[idx, 0], size=[self.args.uttWindowSize, self.args.wordUnits])
            utt_inputs.append(utt_input)

        def my_cond(idx):
            idx = tf.add(idx, 1)
            return tf.less(idx, self.batchSize)

        tf.while_loop(cond=my_cond, body=add_inputs, loop_vars=[idx])

where self.batchSize is a placeholder of tf.int32. Last_outputs is a 2-d tensor. However, when I run the code, tensorflow gives an error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 1596, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 974, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/v-zhaom/OneDrive/speakerRNN/main.py", line 5, in <module>
    speakerTagger.main()
  File "C:/Users/v-zhaom/OneDrive/speakerRNN\speakerChangeTagger\tagger.py", line 152, in main
    self.model = RecurrentModel(self.args, self.textData)
  File "C:/Users/v-zhaom/OneDrive/speakerRNN\speakerChangeTagger\RecurrentModel.py", line 29, in __init__
    self.buildNetWork()
  File "C:/Users/v-zhaom/OneDrive/speakerRNN\speakerChangeTagger\RecurrentModel.py", line 36, in buildNetWork
    context_vectors = self._buildUttNetwork(last_outputs)
  File "C:/Users/v-zhaom/OneDrive/speakerRNN\speakerChangeTagger\RecurrentModel.py", line 136, in _buildUttNetwork
    tf.while_loop(cond=my_cond, body=add_inputs, loop_vars=[idx])
  File "C:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2636, in while_loop
    result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "C:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2469, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "C:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2441, in _BuildLoop
    next_vars.append(_AddNextAndBackEdge(m, v))
  File "C:\Python35\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 635, in _AddNextAndBackEdge
    v = ops.convert_to_tensor(v)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 669, in convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 176, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 165, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 360, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

1 Answer 1

1

The function passed to the body parameter should return a tensor value, not None. Try changing the function to the following.

def add_inputs(idx):
    utt_input = tf.slice(last_outputs, begin=[idx, 0],
    size=[self.args.uttWindowSize, self.args.wordUnits])
    utt_inputs.append(utt_input)
    return tf.constant(0 , dtype=tf.int32 , name="ret_val") #Dummy

From the docs,

body is a callable returning a (possibly nested) tuple, namedtuple or list of tensors of the same arity (length and structure) and types as loop_vars.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.