lingvo icon indicating copy to clipboard operation
lingvo copied to clipboard

tf.broadcast_to does not accept Dimension objects for the shape parameter. TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [Dimension(None), Dimension(None), Dimension(1), Dimension(None)]. Consider casting elements to a supported type.

Open manish-kumar-garg opened this issue 5 years ago • 0 comments

Hi, I am implementing an ASR model and getting error in tf.broadcast_to Below is the part of code in ComputePredictions

    activation = lm_out.last_hidden
    encoder_outputs = tf.transpose(encoder_outputs, [1, 2, 0])    # [batch, depth, time]
    activation = tf.transpose(activation, [0, 2, 1])                           # [batch, depth, time]
    xs = tf.expand_dims(encoder_outputs, axis=2)
    ymat = tf.expand_dims(activation, axis=1)
    sz = [max(i, j) for i, j in zip(xs.shape[:-1], ymat.shape[:-1])]
    xs = tf.broadcast_to(xs,sz+[xs.shape[-1]])
    ymat = tf.broadcast_to(ymat,sz+[ymat.shape[-1]])
    out = tf.concat([xs,ymat], axis=3)

Stack Trace

predictions = self.ComputePredictions(theta, input_batch)
  File "/root/.cache/bazel/_bazel_root/17eb95f0bc03547f4f1319e61997e114/execroot/__main__/bazel-out/k8-opt/bin/lingvo/trainer.runfiles/__main__/lingvo/tasks/asr/model.py", line 292, in ComputePredictions
    xs = tf.broadcast_to(xs,sz+[xs.shape[-1]])
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/gen_array_ops.py", line 925, in broadcast_to
    "BroadcastTo", input=input, shape=shape, name=name)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/op_def_library.py", line 530, in _apply_op_helper
    raise err
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/op_def_library.py", line 527, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/ops.py", line 1296, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/constant_op.py", line 286, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/constant_op.py", line 227, in constant
    allow_broadcast=True)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/constant_op.py", line 265, in _constant_impl
    allow_broadcast=allow_broadcast))
  File "/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/tensor_util.py", line 545, in make_tensor_proto
    "supported type." % (type(values), values))
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [Dimension(None), Dimension(None), Dimension(1), Dimension(None)]. Consider casting elements to a supported type.

manish-kumar-garg avatar Nov 20 '19 12:11 manish-kumar-garg