{
  "id": 270242,
  "title": "How to correctly define efficientnet in tensorflow?",
  "url": "/competitions/g2net-gravitational-wave-detection/discussion/270242",
  "author_name": "",
  "post_date": "2021-09-04T09:07:03.535808200Z",
  "votes": 1,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hi I'm beginner of tensorflow and machine learning.<br>\nI tried some ways to train efficientnet in my tensorflow code.<br>\nI don't understand which is the correct and what is the mistake.</p>\n<h1>--- case A functional API ---</h1>\n<p>input_shape = (69, 193, 1)<br>\ninput_x = tf.keras.Input(shape = input_shape)<br>\nx = tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same')(input_x)<br>\nx = tf.keras.applications.efficientnet.EfficientNetB0(weights='imagenet', include_top=False, input_shape=())(x)<br>\nx = tf.keras.layers.GlobalAveragePooling2D()(x)<br>\nx = tf.keras.layers.Dense(32, activation='relu')(x)<br>\npredictions = tf.keras.layers.Dense(1, activation='sigmoid')(x)<br>\nmodel = tf.keras.models.Model(inputs=input_x, outputs=predictions)</p>\n<h1>--- case B sequential API ---</h1>\n<p>import efficientnet.tfkeras as efn<br>\ninput_shape = (69, 193, 1)<br>\nmodel = tf.keras.Sequential([<br>\n  tf.keras.layers.InputLayer(input_shape=input_shape),<br>\n  tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same'),<br>\n  efn.EfficientNetB0(include_top=False, input_shape=(), weights='imagenet'),<br>\n  tf.keras.layers.GlobalAveragePooling2D(),<br>\n  tf.keras.layers.Dense(32, activation='relu'),<br>\n  tf.keras.layers.Dense(1, activation='sigmoid'),<br>\n  ])</p>\n<p>I was thinking these 2 models are perfectly same but case B gives good roc score over 0.8 and<br>\ncase A gives 0.5 roc score so I guess case B is correct.<br>\ncould you tell me what is the difference and how can I check the mistake about the model.<br>\nAnd also could you give me the example functional API of case B. thanks.</p>",
  "messages": [
    {
      "id": "1502447",
      "postDate": "09/04/2021 09:07:03",
      "content": "<p>Hi I'm beginner of tensorflow and machine learning.<br>\nI tried some ways to train efficientnet in my tensorflow code.<br>\nI don't understand which is the correct and what is the mistake.</p>\n<h1>--- case A functional API ---</h1>\n<p>input_shape = (69, 193, 1)<br>\ninput_x = tf.keras.Input(shape = input_shape)<br>\nx = tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same')(input_x)<br>\nx = tf.keras.applications.efficientnet.EfficientNetB0(weights='imagenet', include_top=False, input_shape=())(x)<br>\nx = tf.keras.layers.GlobalAveragePooling2D()(x)<br>\nx = tf.keras.layers.Dense(32, activation='relu')(x)<br>\npredictions = tf.keras.layers.Dense(1, activation='sigmoid')(x)<br>\nmodel = tf.keras.models.Model(inputs=input_x, outputs=predictions)</p>\n<h1>--- case B sequential API ---</h1>\n<p>import efficientnet.tfkeras as efn<br>\ninput_shape = (69, 193, 1)<br>\nmodel = tf.keras.Sequential([<br>\n  tf.keras.layers.InputLayer(input_shape=input_shape),<br>\n  tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same'),<br>\n  efn.EfficientNetB0(include_top=False, input_shape=(), weights='imagenet'),<br>\n  tf.keras.layers.GlobalAveragePooling2D(),<br>\n  tf.keras.layers.Dense(32, activation='relu'),<br>\n  tf.keras.layers.Dense(1, activation='sigmoid'),<br>\n  ])</p>\n<p>I was thinking these 2 models are perfectly same but case B gives good roc score over 0.8 and<br>\ncase A gives 0.5 roc score so I guess case B is correct.<br>\ncould you tell me what is the difference and how can I check the mistake about the model.<br>\nAnd also could you give me the example functional API of case B. thanks.</p>",
      "rawMarkdown": "Hi I'm beginner of tensorflow and machine learning.\nI tried some ways to train efficientnet in my tensorflow code.\nI don't understand which is the correct and what is the mistake.\n\n# --- case A functional API ---\ninput_shape = (69, 193, 1)\ninput_x = tf.keras.Input(shape = input_shape)\nx = tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same')(input_x)\nx = tf.keras.applications.efficientnet.EfficientNetB0(weights='imagenet', include_top=False, input_shape=())(x)\nx = tf.keras.layers.GlobalAveragePooling2D()(x)\nx = tf.keras.layers.Dense(32, activation='relu')(x)\npredictions = tf.keras.layers.Dense(1, activation='sigmoid')(x)\nmodel = tf.keras.models.Model(inputs=input_x, outputs=predictions)\n\n# --- case B sequential API ---\nimport efficientnet.tfkeras as efn\ninput_shape = (69, 193, 1)\nmodel = tf.keras.Sequential([\n  tf.keras.layers.InputLayer(input_shape=input_shape),\n  tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same'),\n  efn.EfficientNetB0(include_top=False, input_shape=(), weights='imagenet'),\n  tf.keras.layers.GlobalAveragePooling2D(),\n  tf.keras.layers.Dense(32, activation='relu'),\n  tf.keras.layers.Dense(1, activation='sigmoid'),\n  ])\n\nI was thinking these 2 models are perfectly same but case B gives good roc score over 0.8 and\ncase A gives 0.5 roc score so I guess case B is correct.\ncould you tell me what is the difference and how can I check the mistake about the model.\nAnd also could you give me the example functional API of case B. thanks.",
      "votes": null
    },
    {
      "id": "1559956",
      "postDate": "10/27/2021 08:37:15",
      "content": "<p>Hey All,</p>\n<p>Thank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey <a href=\"https://forms.gle/QP9L16niPexozyhu5\" target=\"_blank\">https://forms.gle/QP9L16niPexozyhu5</a>.</p>\n<p>Thank you all,</p>\n<p>Regards,<br>\nChris</p>",
      "rawMarkdown": "Hey All,\n\nThank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey https://forms.gle/QP9L16niPexozyhu5.\n\nThank you all,\n\nRegards,\nChris",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1559956,
      "author_name": "zerafachris",
      "author_url": "",
      "post_date": "10/27/2021 08:37:15",
      "content": "<p>Hey All,</p>\n<p>Thank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey <a href=\"https://forms.gle/QP9L16niPexozyhu5\" target=\"_blank\">https://forms.gle/QP9L16niPexozyhu5</a>.</p>\n<p>Thank you all,</p>\n<p>Regards,<br>\nChris</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1502447": "Hi I'm beginner of tensorflow and machine learning.\nI tried some ways to train efficientnet in my tensorflow code.\nI don't understand which is the correct and what is the mistake.\n\n# --- case A functional API ---\ninput_shape = (69, 193, 1)\ninput_x = tf.keras.Input(shape = input_shape)\nx = tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same')(input_x)\nx = tf.keras.applications.efficientnet.EfficientNetB0(weights='imagenet', include_top=False, input_shape=())(x)\nx = tf.keras.layers.GlobalAveragePooling2D()(x)\nx = tf.keras.layers.Dense(32, activation='relu')(x)\npredictions = tf.keras.layers.Dense(1, activation='sigmoid')(x)\nmodel = tf.keras.models.Model(inputs=input_x, outputs=predictions)\n\n# --- case B sequential API ---\nimport efficientnet.tfkeras as efn\ninput_shape = (69, 193, 1)\nmodel = tf.keras.Sequential([\n  tf.keras.layers.InputLayer(input_shape=input_shape),\n  tf.keras.layers.Conv2D(3, 3, activation='relu', padding='same'),\n  efn.EfficientNetB0(include_top=False, input_shape=(), weights='imagenet'),\n  tf.keras.layers.GlobalAveragePooling2D(),\n  tf.keras.layers.Dense(32, activation='relu'),\n  tf.keras.layers.Dense(1, activation='sigmoid'),\n  ])\n\nI was thinking these 2 models are perfectly same but case B gives good roc score over 0.8 and\ncase A gives 0.5 roc score so I guess case B is correct.\ncould you tell me what is the difference and how can I check the mistake about the model.\nAnd also could you give me the example functional API of case B. thanks.",
    "1559956": "Hey All,\n\nThank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey https://forms.gle/QP9L16niPexozyhu5.\n\nThank you all,\n\nRegards,\nChris"
  },
  "source": "meta"
}