{
  "id": 109995,
  "title": "Best Loss Function?",
  "url": "/competitions/rsna-intracranial-hemorrhage-detection/discussion/109995",
  "author_name": "Bo Peng",
  "post_date": "2019-09-24T03:41:57.061000",
  "votes": 2,
  "comment_count": 6,
  "views": 0,
  "content": "<p>What do you guys think should be the best loss function to use?</p>\n\n<p>i.e. Binary cross entropy</p>",
  "messages": [
    {
      "id": 636343,
      "postDate": "2019-09-29T10:25:24.113Z",
      "content": "<p>Usually it is best to use a loss function that mimics the competition metric. In this case it's probably weighted BCE, with all weights set to 1 except 'ANY's which is 2. (For me this gives LB very close to CV) </p>",
      "rawMarkdown": "Usually it is best to use a loss function that mimics the competition metric. In this case it's probably weighted BCE, with all weights set to 1 except 'ANY's which is 2. (For me this gives LB very close to CV) ",
      "votes": 3,
      "replies": [
        {
          "id": 636392,
          "postDate": "2019-09-29T12:50:19.707Z",
          "content": "<p>So I'm currently trying:\n<code>weight_tensor = torch.tensor([1,1,1,1,1,2], require_grad=False, dtype=torch.float).to(device)</code></p>\n\n<p><code>criterion = BCELossWithLogitsLoss(pos_weight=weight_tensor)</code></p>\n\n<p>Is this similar to what you're using?</p>",
          "rawMarkdown": "So I'm currently trying:\n`weight_tensor = torch.tensor([1,1,1,1,1,2], require_grad=False, dtype=torch.float).to(device)`\n\n`criterion = BCELossWithLogitsLoss(pos_weight=weight_tensor)`\n\nIs this similar to what you're using?"
        },
        {
          "id": 636452,
          "postDate": "2019-09-29T14:57:20.413Z",
          "content": "<p>No. The pos_weight is just for the positive examples. You need to write your own (very simple) loss function to get different weights for the multi-label binary output. </p>",
          "rawMarkdown": "No. The pos_weight is just for the positive examples. You need to write your own (very simple) loss function to get different weights for the multi-label binary output. ",
          "votes": 2
        }
      ]
    },
    {
      "id": 634580,
      "postDate": "2019-09-26T13:12:47.653Z",
      "content": "<p>Binary Focal Loss</p>",
      "rawMarkdown": "Binary Focal Loss",
      "votes": 3,
      "replies": [
        {
          "id": 636167,
          "postDate": "2019-09-28T23:06:56.797Z",
          "content": "<p><a href=\"/orkatz2\">@orkatz2</a> Are you using pytorch? If so, can you share how are you are implementing it? I'm still getting the hang of pytorch and I'm not great with writing my own loss functions. Help is appreciated :)</p>",
          "rawMarkdown": "@orkatz2 Are you using pytorch? If so, can you share how are you are implementing it? I'm still getting the hang of pytorch and I'm not great with writing my own loss functions. Help is appreciated :)"
        }
      ]
    },
    {
      "id": 632776,
      "postDate": "2019-09-24T03:41:57.060Z",
      "content": "<p>What do you guys think should be the best loss function to use?</p>\n\n<p>i.e. Binary cross entropy</p>",
      "rawMarkdown": "What do you guys think should be the best loss function to use?\n\n i.e. Binary cross entropy",
      "votes": 2
    },
    {
      "id": 634247,
      "postDate": "2019-09-26T04:54:27.643Z",
      "content": "<p>bce is the closest to this competition metric. but i will give a try to others like focal loss</p>",
      "rawMarkdown": "bce is the closest to this competition metric. but i will give a try to others like focal loss"
    }
  ],
  "comments": [
    {
      "id": 636343,
      "author_name": "yuval reina",
      "author_url": "",
      "post_date": "2019-09-29T10:25:24.113000",
      "content": "<p>Usually it is best to use a loss function that mimics the competition metric. In this case it's probably weighted BCE, with all weights set to 1 except 'ANY's which is 2. (For me this gives LB very close to CV) </p>",
      "votes": 3,
      "replies": [
        {
          "id": 636392,
          "author_name": "Tim Yee",
          "author_url": "",
          "post_date": "2019-09-29T12:50:19.707000",
          "content": "<p>So I'm currently trying:\n<code>weight_tensor = torch.tensor([1,1,1,1,1,2], require_grad=False, dtype=torch.float).to(device)</code></p>\n\n<p><code>criterion = BCELossWithLogitsLoss(pos_weight=weight_tensor)</code></p>\n\n<p>Is this similar to what you're using?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 636452,
          "author_name": "yuval reina",
          "author_url": "",
          "post_date": "2019-09-29T14:57:20.413000",
          "content": "<p>No. The pos_weight is just for the positive examples. You need to write your own (very simple) loss function to get different weights for the multi-label binary output. </p>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 634580,
      "author_name": "OrKatz",
      "author_url": "",
      "post_date": "2019-09-26T13:12:47.653000",
      "content": "<p>Binary Focal Loss</p>",
      "votes": 3,
      "replies": [
        {
          "id": 636167,
          "author_name": "Tim Yee",
          "author_url": "",
          "post_date": "2019-09-28T23:06:56.797000",
          "content": "<p><a href=\"/orkatz2\">@orkatz2</a> Are you using pytorch? If so, can you share how are you are implementing it? I'm still getting the hang of pytorch and I'm not great with writing my own loss functions. Help is appreciated :)</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 634247,
      "author_name": "DatNT",
      "author_url": "",
      "post_date": "2019-09-26T04:54:27.643000",
      "content": "<p>bce is the closest to this competition metric. but i will give a try to others like focal loss</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "636343": "Usually it is best to use a loss function that mimics the competition metric. In this case it's probably weighted BCE, with all weights set to 1 except 'ANY's which is 2. (For me this gives LB very close to CV) ",
    "634580": "Binary Focal Loss",
    "632776": "What do you guys think should be the best loss function to use?\n\n i.e. Binary cross entropy",
    "634247": "bce is the closest to this competition metric. but i will give a try to others like focal loss"
  }
}