{
  "id": 200077,
  "title": "How load weights off-line?",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/200077",
  "author_name": "",
  "post_date": "2020-11-28T17:48:42.426983300Z",
  "votes": 1,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Sorry, guys, have stupid question - when I train my model using internet (weights = 'imagenet') everything working OK. When i try to use this weights off-line, uploading them, I've got error \"You are trying to load a weight file containing 208 layers into a model with 209 layers\" . .I am trying to use Efficientnet3. What is wrong with this layer q-ties? thanks</p>",
  "messages": [
    {
      "id": "1094539",
      "postDate": "11/28/2020 17:48:42",
      "content": "<p>Sorry, guys, have stupid question - when I train my model using internet (weights = 'imagenet') everything working OK. When i try to use this weights off-line, uploading them, I've got error \"You are trying to load a weight file containing 208 layers into a model with 209 layers\" . .I am trying to use Efficientnet3. What is wrong with this layer q-ties? thanks</p>",
      "rawMarkdown": "Sorry, guys, have stupid question - when I train my model using internet (weights = 'imagenet') everything working OK. When i try to use this weights off-line, uploading them, I've got error \"You are trying to load a weight file containing 208 layers into a model with 209 layers\" . .I am trying to use Efficientnet3. What is wrong with this layer q-ties? thanks",
      "votes": null
    },
    {
      "id": "1094771",
      "postDate": "11/28/2020 22:39:09",
      "content": "<p>Can you provide a code snippet both of training model and inference?</p>\n<p>I find I have to recreate the model for EfficientNet during inference before I can load the model weights.</p>",
      "rawMarkdown": "Can you provide a code snippet both of training model and inference?\n\nI find I have to recreate the model for EfficientNet during inference before I can load the model weights.",
      "votes": null
    },
    {
      "id": "1094836",
      "postDate": "11/29/2020 01:23:15",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/serg132003\" target=\"_blank\">@serg132003</a> , since there is only one layer of difference, I guess it can be, the <code>input</code>, <code>output</code>, or maybe the pooling layer, but to be sure just looking at the code.</p>",
      "rawMarkdown": "Hey @serg132003 , since there is only one layer of difference, I guess it can be, the `input`, `output`, or maybe the pooling layer, but to be sure just looking at the code.",
      "votes": null
    },
    {
      "id": "1095480",
      "postDate": "11/29/2020 16:21:16",
      "content": "<p>I have this error exactly at the beginning of  model:</p>\n<p>batch_size = 32<br>\nimage_size = 300<br>\ninput_shape = (image_size, image_size, 3)<br>\nclasses_to_predict = sorted(training_df.label.unique())</p>\n<h1>effnet_layers = tf.keras.models.load_model(\"../input/tfkeras-22-pretrained-and-vanilla-efficientnet/TF2.2_EfficientNetB3_NoTop_ImageNet.h5\")</h1>\n<p>effnet_layers = EfficientNetB3(weights='../input/efficientnet-keras-noisystudent-weights-b0b7/efficientnet-b3_noisy-student_notop.h5', <br>\n                               include_top=False, input_shape=input_shape)</p>\n<p>Now I see, that not only me have this problem, because AerysS specially loaded weights for bunch of efficientnet models as Data - <a href=\"https://www.kaggle.com/aeryss/tf-keras-22-pretrained-models\" target=\"_blank\">https://www.kaggle.com/aeryss/tf-keras-22-pretrained-models</a>. And when I use them (upper line with #), program works. <br>\nSo I may say, that problem solved, but… still didn't get it - WHY I CAN LOAD ''IMAGENET'' WEIGHTS FROM INTERNET OK  AND HAVE THIS LOST LAYER  IF I TRY TO LOAD REGULAR WEIGHTS LIKE ../input/efficientnetb0b7-keras-weights/efficientnet-b0_weights_tf_dim_ordering_tf_kernels_autoaugment_notop.h5?????????</p>",
      "rawMarkdown": "I have this error exactly at the beginning of  model:\n\nbatch_size = 32\nimage_size = 300\ninput_shape = (image_size, image_size, 3)\nclasses_to_predict = sorted(training_df.label.unique())\n#effnet_layers = tf.keras.models.load_model(\"../input/tfkeras-22-pretrained-and-vanilla-efficientnet/TF2.2_EfficientNetB3_NoTop_ImageNet.h5\")\neffnet_layers = EfficientNetB3(weights='../input/efficientnet-keras-noisystudent-weights-b0b7/efficientnet-b3_noisy-student_notop.h5', \n                               include_top=False, input_shape=input_shape)\n\nNow I see, that not only me have this problem, because AerysS specially loaded weights for bunch of efficientnet models as Data - https://www.kaggle.com/aeryss/tf-keras-22-pretrained-models. And when I use them (upper line with #), program works. \nSo I may say, that problem solved, but... still didn't get it - WHY I CAN LOAD ''IMAGENET'' WEIGHTS FROM INTERNET OK  AND HAVE THIS LOST LAYER  IF I TRY TO LOAD REGULAR WEIGHTS LIKE ../input/efficientnetb0b7-keras-weights/efficientnet-b0_weights_tf_dim_ordering_tf_kernels_autoaugment_notop.h5?????????",
      "votes": null
    },
    {
      "id": "1095495",
      "postDate": "11/29/2020 16:39:11",
      "content": "<p>I presume you load EfficientNetB3 and then add a \"top\" like a global pooling layer and a softmax that puts out 5 targets. Do you add this layer on in your inference notebook?</p>",
      "rawMarkdown": "I presume you load EfficientNetB3 and then add a \"top\" like a global pooling layer and a softmax that puts out 5 targets. Do you add this layer on in your inference notebook?",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1094771,
      "author_name": "richardepstein",
      "author_url": "",
      "post_date": "11/28/2020 22:39:09",
      "content": "<p>Can you provide a code snippet both of training model and inference?</p>\n<p>I find I have to recreate the model for EfficientNet during inference before I can load the model weights.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1095480,
          "author_name": "serg132003",
          "author_url": "",
          "post_date": "11/29/2020 16:21:16",
          "content": "<p>I have this error exactly at the beginning of  model:</p>\n<p>batch_size = 32<br>\nimage_size = 300<br>\ninput_shape = (image_size, image_size, 3)<br>\nclasses_to_predict = sorted(training_df.label.unique())</p>\n<h1>effnet_layers = tf.keras.models.load_model(\"../input/tfkeras-22-pretrained-and-vanilla-efficientnet/TF2.2_EfficientNetB3_NoTop_ImageNet.h5\")</h1>\n<p>effnet_layers = EfficientNetB3(weights='../input/efficientnet-keras-noisystudent-weights-b0b7/efficientnet-b3_noisy-student_notop.h5', <br>\n                               include_top=False, input_shape=input_shape)</p>\n<p>Now I see, that not only me have this problem, because AerysS specially loaded weights for bunch of efficientnet models as Data - <a href=\"https://www.kaggle.com/aeryss/tf-keras-22-pretrained-models\" target=\"_blank\">https://www.kaggle.com/aeryss/tf-keras-22-pretrained-models</a>. And when I use them (upper line with #), program works. <br>\nSo I may say, that problem solved, but… still didn't get it - WHY I CAN LOAD ''IMAGENET'' WEIGHTS FROM INTERNET OK  AND HAVE THIS LOST LAYER  IF I TRY TO LOAD REGULAR WEIGHTS LIKE ../input/efficientnetb0b7-keras-weights/efficientnet-b0_weights_tf_dim_ordering_tf_kernels_autoaugment_notop.h5?????????</p>",
          "votes": null,
          "replies": [
            {
              "id": 1095495,
              "author_name": "richardepstein",
              "author_url": "",
              "post_date": "11/29/2020 16:39:11",
              "content": "<p>I presume you load EfficientNetB3 and then add a \"top\" like a global pooling layer and a softmax that puts out 5 targets. Do you add this layer on in your inference notebook?</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 1094836,
      "author_name": "dimitreoliveira",
      "author_url": "",
      "post_date": "11/29/2020 01:23:15",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/serg132003\" target=\"_blank\">@serg132003</a> , since there is only one layer of difference, I guess it can be, the <code>input</code>, <code>output</code>, or maybe the pooling layer, but to be sure just looking at the code.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1094539": "Sorry, guys, have stupid question - when I train my model using internet (weights = 'imagenet') everything working OK. When i try to use this weights off-line, uploading them, I've got error \"You are trying to load a weight file containing 208 layers into a model with 209 layers\" . .I am trying to use Efficientnet3. What is wrong with this layer q-ties? thanks",
    "1094771": "Can you provide a code snippet both of training model and inference?\n\nI find I have to recreate the model for EfficientNet during inference before I can load the model weights.",
    "1094836": "Hey @serg132003 , since there is only one layer of difference, I guess it can be, the `input`, `output`, or maybe the pooling layer, but to be sure just looking at the code.",
    "1095480": "I have this error exactly at the beginning of  model:\n\nbatch_size = 32\nimage_size = 300\ninput_shape = (image_size, image_size, 3)\nclasses_to_predict = sorted(training_df.label.unique())\n#effnet_layers = tf.keras.models.load_model(\"../input/tfkeras-22-pretrained-and-vanilla-efficientnet/TF2.2_EfficientNetB3_NoTop_ImageNet.h5\")\neffnet_layers = EfficientNetB3(weights='../input/efficientnet-keras-noisystudent-weights-b0b7/efficientnet-b3_noisy-student_notop.h5', \n                               include_top=False, input_shape=input_shape)\n\nNow I see, that not only me have this problem, because AerysS specially loaded weights for bunch of efficientnet models as Data - https://www.kaggle.com/aeryss/tf-keras-22-pretrained-models. And when I use them (upper line with #), program works. \nSo I may say, that problem solved, but... still didn't get it - WHY I CAN LOAD ''IMAGENET'' WEIGHTS FROM INTERNET OK  AND HAVE THIS LOST LAYER  IF I TRY TO LOAD REGULAR WEIGHTS LIKE ../input/efficientnetb0b7-keras-weights/efficientnet-b0_weights_tf_dim_ordering_tf_kernels_autoaugment_notop.h5?????????",
    "1095495": "I presume you load EfficientNetB3 and then add a \"top\" like a global pooling layer and a softmax that puts out 5 targets. Do you add this layer on in your inference notebook?"
  },
  "source": "meta"
}