{
  "id": 111719,
  "title": "Code of weighted log loss is here",
  "url": "/competitions/rsna-intracranial-hemorrhage-detection/discussion/111719",
  "author_name": "Rajnish Chauhan",
  "post_date": "2019-10-08T09:36:03.532000",
  "votes": 8,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Take care of BATCH_SIZE, it  is same as taken in ImageGenerator.</p>\n\n<p>Use \"custom_log_loss\" in model.compile( loss ='customers_log_loss')</p>\n\n<h1>def custom_log_loss(y_true, y_pred):</h1>\n\n<pre><code>#weights_cons = tf.constant([2.0, 1.0, 1.0, 1.0, 1.0, 1.0])\n#loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, weights = tf.broadcast_to(weights_cons, [BATCH_SIZE, 6]))\n\n#loss_val = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_true, logits=y_pred)\n#loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred)\n#print(y_true.shape)\n#print(ck_val)\nreturn loss_val\n</code></pre>",
  "messages": [
    {
      "id": 644078,
      "postDate": "2019-10-08T09:36:03.533Z",
      "content": "<p>Take care of BATCH_SIZE, it  is same as taken in ImageGenerator.</p>\n\n<p>Use \"custom_log_loss\" in model.compile( loss ='customers_log_loss')</p>\n\n<h1>def custom_log_loss(y_true, y_pred):</h1>\n\n<pre><code>#weights_cons = tf.constant([2.0, 1.0, 1.0, 1.0, 1.0, 1.0])\n#loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, weights = tf.broadcast_to(weights_cons, [BATCH_SIZE, 6]))\n\n#loss_val = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_true, logits=y_pred)\n#loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred)\n#print(y_true.shape)\n#print(ck_val)\nreturn loss_val\n</code></pre>",
      "rawMarkdown": "Take care of BATCH_SIZE, it  is same as taken in ImageGenerator.\n\nUse \"custom_log_loss\" in model.compile( loss ='customers_log_loss')\n\n#def custom_log_loss(y_true, y_pred):\n    #weights_cons = tf.constant([2.0, 1.0, 1.0, 1.0, 1.0, 1.0])\n    #loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, weights = tf.broadcast_to(weights_cons, [BATCH_SIZE, 6]))\n\n    #loss_val = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_true, logits=y_pred)\n    #loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred)\n    #print(y_true.shape)\n    #print(ck_val)\n    return loss_val",
      "votes": 8
    },
    {
      "id": 645963,
      "postDate": "2019-10-10T17:06:38.737Z",
      "content": "<p>In case your data is not exact divided by BATCH_SIZE then there could be error. So needed to broadcast tensor dynamically. How to do so need little change in code as below.\nloss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, \n                              weights = <strong>tf.broadcast_to(weights_cons, *tf.shape(y_pred)*</strong>))</p>",
      "rawMarkdown": "In case your data is not exact divided by BATCH_SIZE then there could be error. So needed to broadcast tensor dynamically. How to do so need little change in code as below.\nloss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, \n                              weights = **tf.broadcast_to(weights_cons, *tf.shape(y_pred)***))",
      "votes": 1
    },
    {
      "id": 649456,
      "postDate": "2019-10-15T11:32:06.250Z",
      "content": "<p>Thanks for sharing.</p>",
      "rawMarkdown": "Thanks for sharing."
    }
  ],
  "comments": [
    {
      "id": 645963,
      "author_name": "Rajnish Chauhan",
      "author_url": "",
      "post_date": "2019-10-10T17:06:38.737000",
      "content": "<p>In case your data is not exact divided by BATCH_SIZE then there could be error. So needed to broadcast tensor dynamically. How to do so need little change in code as below.\nloss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, \n                              weights = <strong>tf.broadcast_to(weights_cons, *tf.shape(y_pred)*</strong>))</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 649456,
      "author_name": "LongYin/杰少",
      "author_url": "",
      "post_date": "2019-10-15T11:32:06.250000",
      "content": "<p>Thanks for sharing.</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "644078": "Take care of BATCH_SIZE, it  is same as taken in ImageGenerator.\n\nUse \"custom_log_loss\" in model.compile( loss ='customers_log_loss')\n\n#def custom_log_loss(y_true, y_pred):\n    #weights_cons = tf.constant([2.0, 1.0, 1.0, 1.0, 1.0, 1.0])\n    #loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, weights = tf.broadcast_to(weights_cons, [BATCH_SIZE, 6]))\n\n    #loss_val = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_true, logits=y_pred)\n    #loss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred)\n    #print(y_true.shape)\n    #print(ck_val)\n    return loss_val",
    "645963": "In case your data is not exact divided by BATCH_SIZE then there could be error. So needed to broadcast tensor dynamically. How to do so need little change in code as below.\nloss_val = tf.losses.sigmoid_cross_entropy(y_true, y_pred, \n                              weights = **tf.broadcast_to(weights_cons, *tf.shape(y_pred)***))",
    "649456": "Thanks for sharing."
  }
}