{
  "id": 355114,
  "title": "How to write competition metric in tensorflow",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/355114",
  "author_name": "",
  "post_date": "2022-09-25T13:25:19.558059600Z",
  "votes": 2,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I would like to create custom metrics in tensorflow to match the metrics of this competition as shown in the following discussion, but I don't know how to write the code. If anyone has written the code, I would appreciate it if you could let me know.<br>\n<a href=\"https://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341854\" target=\"_blank\">https://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341854</a></p>",
  "messages": [
    {
      "id": "1954806",
      "postDate": "09/25/2022 13:25:19",
      "content": "<p>I would like to create custom metrics in tensorflow to match the metrics of this competition as shown in the following discussion, but I don't know how to write the code. If anyone has written the code, I would appreciate it if you could let me know.<br>\n<a href=\"https://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341854\" target=\"_blank\">https://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341854</a></p>",
      "rawMarkdown": "I would like to create custom metrics in tensorflow to match the metrics of this competition as shown in the following discussion, but I don't know how to write the code. If anyone has written the code, I would appreciate it if you could let me know.\nhttps://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341854",
      "votes": null
    },
    {
      "id": "1955048",
      "postDate": "09/25/2022 17:11:44",
      "content": "<p>You should only need to change the loss function. Try this:</p>\n<p><code>loss_fn = tf.losses.BinaryCrossEntropy(from_logits=True, reduction=tf.keras.losses.Reduction.NONE)</code></p>",
      "rawMarkdown": "You should only need to change the loss function. Try this:\n\n`loss_fn = tf.losses.BinaryCrossEntropy(from_logits=True, reduction=tf.keras.losses.Reduction.NONE)`",
      "votes": null
    },
    {
      "id": "1955620",
      "postDate": "09/26/2022 04:33:16",
      "content": "<p>Thank you for your reply.<br>\nI also tried to use BinaryCrossEntropy, but I felt that alone it would not take into account the weights specific to this competition, as shown below.</p>\n<p><code>competition_weights = {\n    '-' : torch.tensor([7, 1, 1, 1, 1, 1, 1, 1], dtype=torch.float, device=device),\n    '+' : torch.tensor([14, 2, 2, 2, 2, 2, 2, 2], dtype=torch.float, device=device),\n}</code></p>",
      "rawMarkdown": "Thank you for your reply.\nI also tried to use BinaryCrossEntropy, but I felt that alone it would not take into account the weights specific to this competition, as shown below.\n\n`competition_weights = {\n    '-' : torch.tensor([7, 1, 1, 1, 1, 1, 1, 1], dtype=torch.float, device=device),\n    '+' : torch.tensor([14, 2, 2, 2, 2, 2, 2, 2], dtype=torch.float, device=device),\n}`",
      "votes": null
    },
    {
      "id": "1959972",
      "postDate": "09/28/2022 12:25:57",
      "content": "<p>Look at this notebook, the final function is the correct one, I believe<br>\n<a href=\"https://www.kaggle.com/code/solverworld/rsna2022-comp-metric\" target=\"_blank\">https://www.kaggle.com/code/solverworld/rsna2022-comp-metric</a></p>",
      "rawMarkdown": "Look at this notebook, the final function is the correct one, I believe\nhttps://www.kaggle.com/code/solverworld/rsna2022-comp-metric",
      "votes": null
    },
    {
      "id": "1961897",
      "postDate": "09/29/2022 12:08:03",
      "content": "<p>Thanks for the reply.<br>\nI would like to know the metrics implemented in sensorflow, not in pytorch.</p>",
      "rawMarkdown": "Thanks for the reply.\nI would like to know the metrics implemented in sensorflow, not in pytorch.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1955048,
      "author_name": "samuelcortinhas",
      "author_url": "",
      "post_date": "09/25/2022 17:11:44",
      "content": "<p>You should only need to change the loss function. Try this:</p>\n<p><code>loss_fn = tf.losses.BinaryCrossEntropy(from_logits=True, reduction=tf.keras.losses.Reduction.NONE)</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 1955620,
          "author_name": "kun4qi",
          "author_url": "",
          "post_date": "09/26/2022 04:33:16",
          "content": "<p>Thank you for your reply.<br>\nI also tried to use BinaryCrossEntropy, but I felt that alone it would not take into account the weights specific to this competition, as shown below.</p>\n<p><code>competition_weights = {\n    '-' : torch.tensor([7, 1, 1, 1, 1, 1, 1, 1], dtype=torch.float, device=device),\n    '+' : torch.tensor([14, 2, 2, 2, 2, 2, 2, 2], dtype=torch.float, device=device),\n}</code></p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1959972,
      "author_name": "solverworld",
      "author_url": "",
      "post_date": "09/28/2022 12:25:57",
      "content": "<p>Look at this notebook, the final function is the correct one, I believe<br>\n<a href=\"https://www.kaggle.com/code/solverworld/rsna2022-comp-metric\" target=\"_blank\">https://www.kaggle.com/code/solverworld/rsna2022-comp-metric</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1961897,
          "author_name": "kun4qi",
          "author_url": "",
          "post_date": "09/29/2022 12:08:03",
          "content": "<p>Thanks for the reply.<br>\nI would like to know the metrics implemented in sensorflow, not in pytorch.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1954806": "I would like to create custom metrics in tensorflow to match the metrics of this competition as shown in the following discussion, but I don't know how to write the code. If anyone has written the code, I would appreciate it if you could let me know.\nhttps://www.kaggle.com/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/341854",
    "1955048": "You should only need to change the loss function. Try this:\n\n`loss_fn = tf.losses.BinaryCrossEntropy(from_logits=True, reduction=tf.keras.losses.Reduction.NONE)`",
    "1955620": "Thank you for your reply.\nI also tried to use BinaryCrossEntropy, but I felt that alone it would not take into account the weights specific to this competition, as shown below.\n\n`competition_weights = {\n    '-' : torch.tensor([7, 1, 1, 1, 1, 1, 1, 1], dtype=torch.float, device=device),\n    '+' : torch.tensor([14, 2, 2, 2, 2, 2, 2, 2], dtype=torch.float, device=device),\n}`",
    "1959972": "Look at this notebook, the final function is the correct one, I believe\nhttps://www.kaggle.com/code/solverworld/rsna2022-comp-metric",
    "1961897": "Thanks for the reply.\nI would like to know the metrics implemented in sensorflow, not in pytorch."
  },
  "source": "meta"
}