{
  "id": 425206,
  "title": "ERROR about BCE loss",
  "url": "/competitions/google-research-identify-contrails-reduce-global-warming/discussion/425206",
  "author_name": "E-Max AI",
  "post_date": "2023-07-17T16:31:37.435000",
  "votes": 3,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I use 'self.loss_module = smp.losses.SoftBCEWithLogitsLoss(reduction = 'mean' , smooth_factor = 0.1)' instead of \"self.loss_module = smp.losses.DiceLoss(mode=\"binary\", smooth=config[\"loss_smooth\"])\"</p>\n<p>loss = self.loss_module(preds, labels)</p>\n<p>but ERROR<br>\nValueError: Target size (torch.Size([32, 256, 256])) must be the same as input size (torch.Size([32, 1, 256, 256]))</p>\n<p>How to modify the code</p>",
  "messages": [
    {
      "id": 2348492,
      "postDate": "2023-07-17T17:14:35.547Z",
      "content": "<p>Hi, you can squeeze the preds tensor to match the target size by dropping the extra dimension.</p>",
      "rawMarkdown": "Hi, you can squeeze the preds tensor to match the target size by dropping the extra dimension.",
      "votes": 1
    },
    {
      "id": 2348561,
      "postDate": "2023-07-17T18:12:26.710Z",
      "content": "<p>Simply use:<br>\n<code>y_hat = y_hat.view(target.shape)</code></p>",
      "rawMarkdown": "Simply use:\n`y_hat = y_hat.view(target.shape)`",
      "votes": 2,
      "replies": [
        {
          "id": 2349225,
          "postDate": "2023-07-18T08:42:19.570Z",
          "content": "<p>Thank you very much</p>",
          "rawMarkdown": "Thank you very much",
          "votes": 1
        }
      ]
    },
    {
      "id": 2348445,
      "postDate": "2023-07-17T16:31:37.437Z",
      "content": "<p>I use 'self.loss_module = smp.losses.SoftBCEWithLogitsLoss(reduction = 'mean' , smooth_factor = 0.1)' instead of \"self.loss_module = smp.losses.DiceLoss(mode=\"binary\", smooth=config[\"loss_smooth\"])\"</p>\n<p>loss = self.loss_module(preds, labels)</p>\n<p>but ERROR<br>\nValueError: Target size (torch.Size([32, 256, 256])) must be the same as input size (torch.Size([32, 1, 256, 256]))</p>\n<p>How to modify the code</p>",
      "rawMarkdown": "I use 'self.loss_module = smp.losses.SoftBCEWithLogitsLoss(reduction = 'mean' , smooth_factor = 0.1)' instead of \"self.loss_module = smp.losses.DiceLoss(mode=\"binary\", smooth=config[\"loss_smooth\"])\"\n\nloss = self.loss_module(preds, labels)\n\nbut ERROR\nValueError: Target size (torch.Size([32, 256, 256])) must be the same as input size (torch.Size([32, 1, 256, 256]))\n\nHow to modify the code",
      "votes": 2
    },
    {
      "id": 2350623,
      "postDate": "2023-07-19T10:58:33.553Z",
      "content": "<p>Does BCE loss give better performance?</p>",
      "rawMarkdown": "Does BCE loss give better performance?",
      "replies": [
        {
          "id": 2350954,
          "postDate": "2023-07-19T17:01:41.280Z",
          "content": "<p>No, BCE loss and Dice + BCE loss can not give better performance </p>",
          "rawMarkdown": "No, BCE loss and Dice + BCE loss can not give better performance "
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 2348492,
      "author_name": "Maximiliano Diaz Battan",
      "author_url": "",
      "post_date": "2023-07-17T17:14:35.547000",
      "content": "<p>Hi, you can squeeze the preds tensor to match the target size by dropping the extra dimension.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 2348561,
      "author_name": "Reacher",
      "author_url": "",
      "post_date": "2023-07-17T18:12:26.710000",
      "content": "<p>Simply use:<br>\n<code>y_hat = y_hat.view(target.shape)</code></p>",
      "votes": 2,
      "replies": [
        {
          "id": 2349225,
          "author_name": "E-Max AI",
          "author_url": "",
          "post_date": "2023-07-18T08:42:19.570000",
          "content": "<p>Thank you very much</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 2350623,
      "author_name": "william.wu",
      "author_url": "",
      "post_date": "2023-07-19T10:58:33.553000",
      "content": "<p>Does BCE loss give better performance?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2350954,
          "author_name": "E-Max AI",
          "author_url": "",
          "post_date": "2023-07-19T17:01:41.280000",
          "content": "<p>No, BCE loss and Dice + BCE loss can not give better performance </p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2348492": "Hi, you can squeeze the preds tensor to match the target size by dropping the extra dimension.",
    "2348561": "Simply use:\n`y_hat = y_hat.view(target.shape)`",
    "2348445": "I use 'self.loss_module = smp.losses.SoftBCEWithLogitsLoss(reduction = 'mean' , smooth_factor = 0.1)' instead of \"self.loss_module = smp.losses.DiceLoss(mode=\"binary\", smooth=config[\"loss_smooth\"])\"\n\nloss = self.loss_module(preds, labels)\n\nbut ERROR\nValueError: Target size (torch.Size([32, 256, 256])) must be the same as input size (torch.Size([32, 1, 256, 256]))\n\nHow to modify the code",
    "2350623": "Does BCE loss give better performance?"
  }
}