{
  "id": 397288,
  "title": "Modified DICE Coefficient Implementation",
  "url": "/competitions/vesuvius-challenge-ink-detection/discussion/397288",
  "author_name": "",
  "post_date": "2023-03-24T21:54:18.565182600Z",
  "votes": 34,
  "comment_count": 6,
  "views": 0,
  "content": "<pre><code> ():\n\n    \n    preds = torch.sigmoid(preds)\n\n    \n    preds = preds.view(-).()\n    targets = targets.view(-).()\n\n    y_true_count = targets.()\n    ctp = preds[targets==].()\n    cfp = preds[targets==].()\n    beta_squared = beta * beta\n\n    c_precision = ctp / (ctp + cfp + smooth)\n    c_recall = ctp / (y_true_count + smooth)\n    dice = ( + beta_squared) * (c_precision * c_recall) / (beta_squared * c_precision + c_recall + smooth)\n\n     dice\n</code></pre>",
  "messages": [
    {
      "id": "2195751",
      "postDate": "03/24/2023 21:54:18",
      "content": "<pre><code> ():\n\n    \n    preds = torch.sigmoid(preds)\n\n    \n    preds = preds.view(-).()\n    targets = targets.view(-).()\n\n    y_true_count = targets.()\n    ctp = preds[targets==].()\n    cfp = preds[targets==].()\n    beta_squared = beta * beta\n\n    c_precision = ctp / (ctp + cfp + smooth)\n    c_recall = ctp / (y_true_count + smooth)\n    dice = ( + beta_squared) * (c_precision * c_recall) / (beta_squared * c_precision + c_recall + smooth)\n\n     dice\n</code></pre>",
      "rawMarkdown": "```python\ndef dice_coef_torch(preds, targets, beta=0.5, smooth=1e-5):\n\n    #comment out if your model contains a sigmoid or equivalent activation layer\n    preds = torch.sigmoid(preds)\n\n    # flatten label and prediction tensors\n    preds = preds.view(-1).float()\n    targets = targets.view(-1).float()\n\n    y_true_count = targets.sum()\n    ctp = preds[targets==1].sum()\n    cfp = preds[targets==0].sum()\n    beta_squared = beta * beta\n\n    c_precision = ctp / (ctp + cfp + smooth)\n    c_recall = ctp / (y_true_count + smooth)\n    dice = (1 + beta_squared) * (c_precision * c_recall) / (beta_squared * c_precision + c_recall + smooth)\n\n    return dice\n```",
      "votes": null
    },
    {
      "id": "2201057",
      "postDate": "03/29/2023 02:36:33",
      "content": "<p>hello,I want to ask, is this the F0.5 score and does it work ok?</p>",
      "rawMarkdown": "hello,I want to ask, is this the F0.5 score and does it work ok?",
      "votes": null
    },
    {
      "id": "2205790",
      "postDate": "04/01/2023 22:55:48",
      "content": "<p>Yes, this calculates the F0.5 score. I am using this code.</p>",
      "rawMarkdown": "Yes, this calculates the F0.5 score. I am using this code.",
      "votes": null
    },
    {
      "id": "2207057",
      "postDate": "04/03/2023 04:49:34",
      "content": "<p>is 2D convolutions better than 3D convolutions in your experimentations?</p>",
      "rawMarkdown": "is 2D convolutions better than 3D convolutions in your experimentations?",
      "votes": null
    },
    {
      "id": "2208171",
      "postDate": "04/03/2023 21:04:24",
      "content": "<p>I didn't try 2D convolutions in my experiment, I only experimented with 3D convolutions. It seems that 3D convolutions are suitable for this problem. I am planning to try 2D convolutions in the future.</p>",
      "rawMarkdown": "I didn't try 2D convolutions in my experiment, I only experimented with 3D convolutions. It seems that 3D convolutions are suitable for this problem. I am planning to try 2D convolutions in the future.",
      "votes": null
    },
    {
      "id": "2250632",
      "postDate": "05/08/2023 17:30:16",
      "content": "<p>Thank you. Your modified dice loss works pretty well. Have you experimented with the value of the smooth coefficient ( does it matter at all)? Also, I’ve seen some modifications with a smoothing factor in the numerator and denominator, would you know the reasoning behind using it in both the numerator and denominator? </p>",
      "rawMarkdown": "Thank you. Your modified dice loss works pretty well. Have you experimented with the value of the smooth coefficient ( does it matter at all)? Also, I’ve seen some modifications with a smoothing factor in the numerator and denominator, would you know the reasoning behind using it in both the numerator and denominator?",
      "votes": null
    },
    {
      "id": "2250943",
      "postDate": "05/08/2023 23:36:28",
      "content": "<blockquote>\n  <p>Have you experimented with the value of the smooth coefficient ( does it matter at all)?</p>\n</blockquote>\n<p>The smooth factor is used to avoid division by zero. I have not adjusted its value.</p>\n<blockquote>\n  <p>would you know the reasoning behind using it in both the numerator and denominator?</p>\n</blockquote>\n<p>I don't know…</p>",
      "rawMarkdown": "> Have you experimented with the value of the smooth coefficient ( does it matter at all)?\n> \n\nThe smooth factor is used to avoid division by zero. I have not adjusted its value.\n\n> would you know the reasoning behind using it in both the numerator and denominator?\n> \n\nI don't know…",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2201057,
      "author_name": "chingllc",
      "author_url": "",
      "post_date": "03/29/2023 02:36:33",
      "content": "<p>hello,I want to ask, is this the F0.5 score and does it work ok?</p>",
      "votes": null,
      "replies": [
        {
          "id": 2205790,
          "author_name": "tmyok1984",
          "author_url": "",
          "post_date": "04/01/2023 22:55:48",
          "content": "<p>Yes, this calculates the F0.5 score. I am using this code.</p>",
          "votes": null,
          "replies": [
            {
              "id": 2207057,
              "author_name": "chingllc",
              "author_url": "",
              "post_date": "04/03/2023 04:49:34",
              "content": "<p>is 2D convolutions better than 3D convolutions in your experimentations?</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2208171,
                  "author_name": "tmyok1984",
                  "author_url": "",
                  "post_date": "04/03/2023 21:04:24",
                  "content": "<p>I didn't try 2D convolutions in my experiment, I only experimented with 3D convolutions. It seems that 3D convolutions are suitable for this problem. I am planning to try 2D convolutions in the future.</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 2250632,
      "author_name": "gregoryeritsyan",
      "author_url": "",
      "post_date": "05/08/2023 17:30:16",
      "content": "<p>Thank you. Your modified dice loss works pretty well. Have you experimented with the value of the smooth coefficient ( does it matter at all)? Also, I’ve seen some modifications with a smoothing factor in the numerator and denominator, would you know the reasoning behind using it in both the numerator and denominator? </p>",
      "votes": null,
      "replies": [
        {
          "id": 2250943,
          "author_name": "tmyok1984",
          "author_url": "",
          "post_date": "05/08/2023 23:36:28",
          "content": "<blockquote>\n  <p>Have you experimented with the value of the smooth coefficient ( does it matter at all)?</p>\n</blockquote>\n<p>The smooth factor is used to avoid division by zero. I have not adjusted its value.</p>\n<blockquote>\n  <p>would you know the reasoning behind using it in both the numerator and denominator?</p>\n</blockquote>\n<p>I don't know…</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2195751": "```python\ndef dice_coef_torch(preds, targets, beta=0.5, smooth=1e-5):\n\n    #comment out if your model contains a sigmoid or equivalent activation layer\n    preds = torch.sigmoid(preds)\n\n    # flatten label and prediction tensors\n    preds = preds.view(-1).float()\n    targets = targets.view(-1).float()\n\n    y_true_count = targets.sum()\n    ctp = preds[targets==1].sum()\n    cfp = preds[targets==0].sum()\n    beta_squared = beta * beta\n\n    c_precision = ctp / (ctp + cfp + smooth)\n    c_recall = ctp / (y_true_count + smooth)\n    dice = (1 + beta_squared) * (c_precision * c_recall) / (beta_squared * c_precision + c_recall + smooth)\n\n    return dice\n```",
    "2201057": "hello,I want to ask, is this the F0.5 score and does it work ok?",
    "2205790": "Yes, this calculates the F0.5 score. I am using this code.",
    "2207057": "is 2D convolutions better than 3D convolutions in your experimentations?",
    "2208171": "I didn't try 2D convolutions in my experiment, I only experimented with 3D convolutions. It seems that 3D convolutions are suitable for this problem. I am planning to try 2D convolutions in the future.",
    "2250632": "Thank you. Your modified dice loss works pretty well. Have you experimented with the value of the smooth coefficient ( does it matter at all)? Also, I’ve seen some modifications with a smoothing factor in the numerator and denominator, would you know the reasoning behind using it in both the numerator and denominator?",
    "2250943": "> Have you experimented with the value of the smooth coefficient ( does it matter at all)?\n> \n\nThe smooth factor is used to avoid division by zero. I have not adjusted its value.\n\n> would you know the reasoning behind using it in both the numerator and denominator?\n> \n\nI don't know…"
  },
  "source": "meta"
}