Ask ValueError: Failed to convert a NumPy array to a Tensor (Unsupported␣ ,→object type list), worked on 2.0.0-beta1

<em>Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template</em>

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10/Juniper lab
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Notebook
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 2.2.0-rc3
  • Python version: 3.8.1
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: no idea
  • GPU model and memory: Geforce GTX 960M

You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with:

  1. TF 1.0: python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
  2. TF 2.0: python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"

Describe the current behavior I get an error when call with ValueError: Failed to convert a NumPy array to a Tensor (Unsupported␣ ,→object type list), see attachment Answer.Tensorflow.pad.sequence.feature.column.DenseFeatures.pdf

Describe the expected behavior I tried to use this example

It looks like it was running on 2.0.0-beta1, but not more in the current version. You can use this notebook to reproduce the case.

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook. You need to adapt the path the the csv file which will also be available in the repository.

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.


Answer questions aaudiber

The problem is that from_tensor_slices needs to convert its input into a Tensor, but the given input contains variable-length numpy lists, which cannot be converted into tensors (tensors must be rectangular). You can get the same error message by running

a = np.array([[1, 2, 3], [4, 5]], dtype=object)

This error appears to occur even in tensorflow 2.0.0-beta1, so it doesn't look like a regression.

To make this work, you need to pad the dataframe's lists so that they are the same length.


Related questions

ModuleNotFoundError: No module named 'tensorflow.contrib' hot 8
Error occurred when finalizing GeneratorDataset iterator hot 6
ModuleNotFoundError: No module named 'tensorflow.contrib'
When importing TensorFlow, error loading Hadoop
tf.keras.layers.Conv1DTranspose ?
tensorflow-gpu CUPTI errors hot 4
[TF 2.0] tf.keras.optimizers.Adam hot 4
Lossy conversion from float32 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning. hot 4
TF2.0 AutoGraph issue hot 4
Tf.Keras metrics issue hot 4
module 'tensorflow' has no attribute 'ConfigProto' hot 4
TF 2.0 'Tensor' object has no attribute 'numpy' while using .numpy() although eager execution enabled by default hot 4
ModuleNotFoundError: No module named 'tensorflow.examples.tutorials' hot 4
AttributeError: module &#39;tensorflow.python.framework.op_def_registry&#39; has no attribute &#39;register_op_list&#39; hot 4
tensorflow2.0 detected 'xla_gpu' , but 'gpu' expected hot 3
Github User Rank List