{
  "id": 232652,
  "title": "ValueError: operands could not be broadcast together with shapes",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/232652",
  "author_name": "",
  "post_date": "2021-04-14T17:34:44.374180100Z",
  "votes": 1,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Has anyone encounter <code>ValueError: operands could not be broadcast together with shapes</code> ? </p>\n<pre><code>---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\n&lt;ipython-input-15-61daffd1399c&gt; in &lt;module&gt;\n    89 \n    90             pred = cv2.resize(pred, (WINDOW, WINDOW))\n---&gt; 91             preds[x1:x2,y1:y2] += (pred &gt; THRESHOLD).astype(np.uint8)\n    92 \n    93 \n\nValueError: operands could not be broadcast together with shapes (1024,1024) (1024,1024,256) (1024,1024) \n</code></pre>\n<p>I don't run into this problem when I use Unet/EfficientNet. But, only when I switch to a different model. </p>",
  "messages": [
    {
      "id": "1273837",
      "postDate": "04/14/2021 17:34:44",
      "content": "<p>Has anyone encounter <code>ValueError: operands could not be broadcast together with shapes</code> ? </p>\n<pre><code>---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\n&lt;ipython-input-15-61daffd1399c&gt; in &lt;module&gt;\n    89 \n    90             pred = cv2.resize(pred, (WINDOW, WINDOW))\n---&gt; 91             preds[x1:x2,y1:y2] += (pred &gt; THRESHOLD).astype(np.uint8)\n    92 \n    93 \n\nValueError: operands could not be broadcast together with shapes (1024,1024) (1024,1024,256) (1024,1024) \n</code></pre>\n<p>I don't run into this problem when I use Unet/EfficientNet. But, only when I switch to a different model. </p>",
      "rawMarkdown": "Has anyone encounter `ValueError: operands could not be broadcast together with shapes` ? \n\n\n```\n---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\n<ipython-input-15-61daffd1399c> in <module>\n    89 \n    90             pred = cv2.resize(pred, (WINDOW, WINDOW))\n---> 91             preds[x1:x2,y1:y2] += (pred > THRESHOLD).astype(np.uint8)\n    92 \n    93 \n\nValueError: operands could not be broadcast together with shapes (1024,1024) (1024,1024,256) (1024,1024) \n```\n\nI don't run into this problem when I use Unet/EfficientNet. But, only when I switch to a different model.",
      "votes": null
    },
    {
      "id": "1274004",
      "postDate": "04/14/2021 21:59:58",
      "content": "<p><a href=\"https://www.kaggle.com/dskswu\" target=\"_blank\">@dskswu</a> I had it once or twice…not exactly sure what was the root cause. Check the shape of pred. Earlier in your code before or after prediction you don't have the correct size anymore. But difficult to see with only these 2 lines.</p>",
      "rawMarkdown": "dskswu I had it once or twice...not exactly sure what was the root cause. Check the shape of pred. Earlier in your code before or after prediction you don't have the correct size anymore. But difficult to see with only these 2 lines.",
      "votes": null
    },
    {
      "id": "1274059",
      "postDate": "04/15/2021 00:07:01",
      "content": "<p><a href=\"https://www.kaggle.com/rsmit\" target=\"_blank\">@rsmit</a> I'm using this <a href=\"https://www.kaggle.com/drzhuzhe/efficientnet-linknet-or-unet?scriptVersionId=59679240\" target=\"_blank\">public kernel </a>.  </p>\n<p>It's weird. I get this error when I use a deep supervision unet model, but not when I use any of the unets with different backbones. </p>",
      "rawMarkdown": "rsmit I'm using this [public kernel ](https://www.kaggle.com/drzhuzhe/efficientnet-linknet-or-unet?scriptVersionId=59679240).  \n\nIt's weird. I get this error when I use a deep supervision unet model, but not when I use any of the unets with different backbones.",
      "votes": null
    },
    {
      "id": "1274235",
      "postDate": "04/15/2021 06:07:22",
      "content": "<p><a href=\"https://www.kaggle.com/dskswu\" target=\"_blank\">@dskswu</a> Ahh Ok…with a deep supervision model it is actually not weird ;-). Deep Supervision models have multiple output layers. For example if the model has 5 total layers there are the 4 intermediary layers and your final output layer. With a Non Deep Supervision model you can just use the output but for a deep supervision you need to select the final output layer from your prediction. </p>\n<p>Your output shape will be something like (5, 1024, 1024). Slice it to get the exact layer that you need….then you will have a valid (1024, 1024) mask as output that you can use.</p>\n<p>Check with the exact model setup how much total layers you have. That should work. Good luck!</p>",
      "rawMarkdown": "dskswu Ahh Ok...with a deep supervision model it is actually not weird ;-). Deep Supervision models have multiple output layers. For example if the model has 5 total layers there are the 4 intermediary layers and your final output layer. With a Non Deep Supervision model you can just use the output but for a deep supervision you need to select the final output layer from your prediction. \n\nYour output shape will be something like (5, 1024, 1024). Slice it to get the exact layer that you need....then you will have a valid (1024, 1024) mask as output that you can use.\n\nCheck with the exact model setup how much total layers you have. That should work. Good luck!",
      "votes": null
    },
    {
      "id": "1274841",
      "postDate": "04/15/2021 16:50:47",
      "content": "<p>Thank you! 😃💯</p>",
      "rawMarkdown": "Thank you! 😃💯",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1274004,
      "author_name": "rsmits",
      "author_url": "",
      "post_date": "04/14/2021 21:59:58",
      "content": "<p><a href=\"https://www.kaggle.com/dskswu\" target=\"_blank\">@dskswu</a> I had it once or twice…not exactly sure what was the root cause. Check the shape of pred. Earlier in your code before or after prediction you don't have the correct size anymore. But difficult to see with only these 2 lines.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1274059,
          "author_name": "dskswu",
          "author_url": "",
          "post_date": "04/15/2021 00:07:01",
          "content": "<p><a href=\"https://www.kaggle.com/rsmit\" target=\"_blank\">@rsmit</a> I'm using this <a href=\"https://www.kaggle.com/drzhuzhe/efficientnet-linknet-or-unet?scriptVersionId=59679240\" target=\"_blank\">public kernel </a>.  </p>\n<p>It's weird. I get this error when I use a deep supervision unet model, but not when I use any of the unets with different backbones. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1274235,
          "author_name": "rsmits",
          "author_url": "",
          "post_date": "04/15/2021 06:07:22",
          "content": "<p><a href=\"https://www.kaggle.com/dskswu\" target=\"_blank\">@dskswu</a> Ahh Ok…with a deep supervision model it is actually not weird ;-). Deep Supervision models have multiple output layers. For example if the model has 5 total layers there are the 4 intermediary layers and your final output layer. With a Non Deep Supervision model you can just use the output but for a deep supervision you need to select the final output layer from your prediction. </p>\n<p>Your output shape will be something like (5, 1024, 1024). Slice it to get the exact layer that you need….then you will have a valid (1024, 1024) mask as output that you can use.</p>\n<p>Check with the exact model setup how much total layers you have. That should work. Good luck!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1274841,
          "author_name": "dskswu",
          "author_url": "",
          "post_date": "04/15/2021 16:50:47",
          "content": "<p>Thank you! 😃💯</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1273837": "Has anyone encounter `ValueError: operands could not be broadcast together with shapes` ? \n\n\n```\n---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\n<ipython-input-15-61daffd1399c> in <module>\n    89 \n    90             pred = cv2.resize(pred, (WINDOW, WINDOW))\n---> 91             preds[x1:x2,y1:y2] += (pred > THRESHOLD).astype(np.uint8)\n    92 \n    93 \n\nValueError: operands could not be broadcast together with shapes (1024,1024) (1024,1024,256) (1024,1024) \n```\n\nI don't run into this problem when I use Unet/EfficientNet. But, only when I switch to a different model.",
    "1274004": "dskswu I had it once or twice...not exactly sure what was the root cause. Check the shape of pred. Earlier in your code before or after prediction you don't have the correct size anymore. But difficult to see with only these 2 lines.",
    "1274059": "rsmit I'm using this [public kernel ](https://www.kaggle.com/drzhuzhe/efficientnet-linknet-or-unet?scriptVersionId=59679240).  \n\nIt's weird. I get this error when I use a deep supervision unet model, but not when I use any of the unets with different backbones.",
    "1274235": "dskswu Ahh Ok...with a deep supervision model it is actually not weird ;-). Deep Supervision models have multiple output layers. For example if the model has 5 total layers there are the 4 intermediary layers and your final output layer. With a Non Deep Supervision model you can just use the output but for a deep supervision you need to select the final output layer from your prediction. \n\nYour output shape will be something like (5, 1024, 1024). Slice it to get the exact layer that you need....then you will have a valid (1024, 1024) mask as output that you can use.\n\nCheck with the exact model setup how much total layers you have. That should work. Good luck!",
    "1274841": "Thank you! 😃💯"
  },
  "source": "meta"
}