{
  "id": 210608,
  "title": "Convert list into Tensor",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/210608",
  "author_name": "Divyanshu Yadav",
  "post_date": "2021-01-11T12:51:04.759000",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I have a list that has NumPy arrays in it. Each array has a different size.</p>\n<p><strong>How can I convert that list into a Tensor?</strong></p>\n<p>My main objective is to feed that tensor as a input. Unet by default converts the input into the tensor using <code>tf.convert_to_tensor</code> function. </p>\n<p><strong>I have Tried:</strong><br>\n<code>tf.convert_to_tensor(tf.ragged.constant(images))</code><br>\n<em>Output:</em> <code>ValueError: TypeError: object of type 'RaggedTensor' has no len()</code></p>\n<p><code>tf.convert_to_tensor(images)</code><br>\n<em>Output:</em> <code>ValueError: Can't convert non-rectangular Python sequence to Tensor.</code></p>\n<p><strong><em>Training Part for  images (numpy array)</em></strong></p>\n<blockquote>\n  <p>model.fit(<br>\n     np.expand_dims(images,0),np.expand_dims(masks,0),<br>\n     batch_size=16,<br>\n     epochs=1<br>\n  )</p>\n</blockquote>\n<p><code>ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).</code></p>",
  "messages": [
    {
      "id": 1148871,
      "postDate": "2021-01-11T12:51:04.760Z",
      "content": "<p>I have a list that has NumPy arrays in it. Each array has a different size.</p>\n<p><strong>How can I convert that list into a Tensor?</strong></p>\n<p>My main objective is to feed that tensor as a input. Unet by default converts the input into the tensor using <code>tf.convert_to_tensor</code> function. </p>\n<p><strong>I have Tried:</strong><br>\n<code>tf.convert_to_tensor(tf.ragged.constant(images))</code><br>\n<em>Output:</em> <code>ValueError: TypeError: object of type 'RaggedTensor' has no len()</code></p>\n<p><code>tf.convert_to_tensor(images)</code><br>\n<em>Output:</em> <code>ValueError: Can't convert non-rectangular Python sequence to Tensor.</code></p>\n<p><strong><em>Training Part for  images (numpy array)</em></strong></p>\n<blockquote>\n  <p>model.fit(<br>\n     np.expand_dims(images,0),np.expand_dims(masks,0),<br>\n     batch_size=16,<br>\n     epochs=1<br>\n  )</p>\n</blockquote>\n<p><code>ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).</code></p>",
      "rawMarkdown": "I have a list that has NumPy arrays in it. Each array has a different size.\n\n**How can I convert that list into a Tensor?**\n\nMy main objective is to feed that tensor as a input. Unet by default converts the input into the tensor using `tf.convert_to_tensor` function. \n\n**I have Tried:**\n`tf.convert_to_tensor(tf.ragged.constant(images))`\n*Output:* `ValueError: TypeError: object of type 'RaggedTensor' has no len()`\n\n`tf.convert_to_tensor(images)`\n*Output:* `ValueError: Can't convert non-rectangular Python sequence to Tensor.`\n\n\n***Training Part for  images (numpy array)***\n>model.fit(\n   np.expand_dims(images,0),np.expand_dims(masks,0),\n   batch_size=16,\n   epochs=1\n)\n\n`ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).`\n ",
      "votes": 1
    },
    {
      "id": 1149743,
      "postDate": "2021-01-12T05:24:22.733Z",
      "rawMarkdown": "",
      "isDeleted": true,
      "replies": [
        {
          "id": 1149778,
          "postDate": "2021-01-12T06:16:33.477Z",
          "content": "<p>No. They all have different shape. That's why i tried ragged constant but it didn't work. </p>",
          "rawMarkdown": "No. They all have different shape. That's why i tried ragged constant but it didn't work. "
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1149743,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-01-12T05:24:22.733000",
      "content": "",
      "votes": 0,
      "replies": [
        {
          "id": 1149778,
          "author_name": "Divyanshu Yadav",
          "author_url": "",
          "post_date": "2021-01-12T06:16:33.477000",
          "content": "<p>No. They all have different shape. That's why i tried ragged constant but it didn't work. </p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1148871": "I have a list that has NumPy arrays in it. Each array has a different size.\n\n**How can I convert that list into a Tensor?**\n\nMy main objective is to feed that tensor as a input. Unet by default converts the input into the tensor using `tf.convert_to_tensor` function. \n\n**I have Tried:**\n`tf.convert_to_tensor(tf.ragged.constant(images))`\n*Output:* `ValueError: TypeError: object of type 'RaggedTensor' has no len()`\n\n`tf.convert_to_tensor(images)`\n*Output:* `ValueError: Can't convert non-rectangular Python sequence to Tensor.`\n\n\n***Training Part for  images (numpy array)***\n>model.fit(\n   np.expand_dims(images,0),np.expand_dims(masks,0),\n   batch_size=16,\n   epochs=1\n)\n\n`ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).`\n ",
    "1149743": ""
  }
}