{
  "id": 165402,
  "title": "Dense layer problem",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/165402",
  "author_name": "",
  "post_date": "2020-07-09T15:34:39.267802500Z",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2F7b7af32e453c21bd5b5875111cd33057%2FAnnotation%202020-07-09%20205439.jpg?generation=1594308693466291&amp;alt=media\" alt=\"\"></p>\n\n<p>When I set Dense unit = 1 (as shown above), I get this error : </p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Ff76ac65a64118ffc882adad5528918f4%2Fer.jpg?generation=1594308747077190&amp;alt=media\" alt=\"\"></p>\n\n<p>But, when I set Dense unit = 2, it starts working fine.</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Fcf74a0cc55a25ee51260a9cff7b6d220%2FAnnotation%202020-07-09%20205633.jpg?generation=1594308811069151&amp;alt=media\" alt=\"\"></p>\n\n<p>Can someone help me with this please?</p>",
  "messages": [
    {
      "id": "921831",
      "postDate": "07/09/2020 15:34:39",
      "content": "<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2F7b7af32e453c21bd5b5875111cd33057%2FAnnotation%202020-07-09%20205439.jpg?generation=1594308693466291&amp;alt=media\" alt=\"\"></p>\n\n<p>When I set Dense unit = 1 (as shown above), I get this error : </p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Ff76ac65a64118ffc882adad5528918f4%2Fer.jpg?generation=1594308747077190&amp;alt=media\" alt=\"\"></p>\n\n<p>But, when I set Dense unit = 2, it starts working fine.</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Fcf74a0cc55a25ee51260a9cff7b6d220%2FAnnotation%202020-07-09%20205633.jpg?generation=1594308811069151&amp;alt=media\" alt=\"\"></p>\n\n<p>Can someone help me with this please?</p>",
      "rawMarkdown": "![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2F7b7af32e453c21bd5b5875111cd33057%2FAnnotation%202020-07-09%20205439.jpg?generation=1594308693466291&amp;alt=media)\n\nWhen I set Dense unit = 1 (as shown above), I get this error : \n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Ff76ac65a64118ffc882adad5528918f4%2Fer.jpg?generation=1594308747077190&amp;alt=media)\n\nBut, when I set Dense unit = 2, it starts working fine.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Fcf74a0cc55a25ee51260a9cff7b6d220%2FAnnotation%202020-07-09%20205633.jpg?generation=1594308811069151&amp;alt=media)\n\nCan someone help me with this please?",
      "votes": null
    },
    {
      "id": "921838",
      "postDate": "07/09/2020 15:42:53",
      "content": "<p>I would use this </p>\n\n<p><code>\nbase_model =tf.keras.applications.VGG19(include_top=False, input_shape=(*IMAGE_SIZE, 3), weights='imagenet')\nglobal_average_layer = tf.keras.layers.GlobalAveragePooling2D()\nprediction_layer = tf.keras.layers.Dense(1, activation='sigmoid')\nmodel = tf.keras.Sequential([\n          base_model,\n          global_average_layer,\n          prediction_layer\n          ])\n</code></p>",
      "rawMarkdown": "I would use this \n\n```\nbase_model =tf.keras.applications.VGG19(include_top=False, input_shape=(*IMAGE_SIZE, 3), weights='imagenet')\nglobal_average_layer = tf.keras.layers.GlobalAveragePooling2D()\nprediction_layer = tf.keras.layers.Dense(1, activation='sigmoid')\nmodel = tf.keras.Sequential([\n          base_model,\n          global_average_layer,\n          prediction_layer\n          ])\n```",
      "votes": null
    },
    {
      "id": "922570",
      "postDate": "07/10/2020 07:53:27",
      "content": "<p>This is probably happening because your target value is one hot encoded. That is why it is searching for two units in the final layer since the total number of classes is 2. If you want it to work with a single dense layer unit then do not one hot encode the target value</p>",
      "rawMarkdown": "This is probably happening because your target value is one hot encoded. That is why it is searching for two units in the final layer since the total number of classes is 2. If you want it to work with a single dense layer unit then do not one hot encode the target value",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 921838,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "07/09/2020 15:42:53",
      "content": "<p>I would use this </p>\n\n<p><code>\nbase_model =tf.keras.applications.VGG19(include_top=False, input_shape=(*IMAGE_SIZE, 3), weights='imagenet')\nglobal_average_layer = tf.keras.layers.GlobalAveragePooling2D()\nprediction_layer = tf.keras.layers.Dense(1, activation='sigmoid')\nmodel = tf.keras.Sequential([\n          base_model,\n          global_average_layer,\n          prediction_layer\n          ])\n</code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 922570,
      "author_name": "aryanpandey1109",
      "author_url": "",
      "post_date": "07/10/2020 07:53:27",
      "content": "<p>This is probably happening because your target value is one hot encoded. That is why it is searching for two units in the final layer since the total number of classes is 2. If you want it to work with a single dense layer unit then do not one hot encode the target value</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "921831": "![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2F7b7af32e453c21bd5b5875111cd33057%2FAnnotation%202020-07-09%20205439.jpg?generation=1594308693466291&amp;alt=media)\n\nWhen I set Dense unit = 1 (as shown above), I get this error : \n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Ff76ac65a64118ffc882adad5528918f4%2Fer.jpg?generation=1594308747077190&amp;alt=media)\n\nBut, when I set Dense unit = 2, it starts working fine.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4241581%2Fcf74a0cc55a25ee51260a9cff7b6d220%2FAnnotation%202020-07-09%20205633.jpg?generation=1594308811069151&amp;alt=media)\n\nCan someone help me with this please?",
    "921838": "I would use this \n\n```\nbase_model =tf.keras.applications.VGG19(include_top=False, input_shape=(*IMAGE_SIZE, 3), weights='imagenet')\nglobal_average_layer = tf.keras.layers.GlobalAveragePooling2D()\nprediction_layer = tf.keras.layers.Dense(1, activation='sigmoid')\nmodel = tf.keras.Sequential([\n          base_model,\n          global_average_layer,\n          prediction_layer\n          ])\n```",
    "922570": "This is probably happening because your target value is one hot encoded. That is why it is searching for two units in the final layer since the total number of classes is 2. If you want it to work with a single dense layer unit then do not one hot encode the target value"
  },
  "source": "meta"
}