{
  "id": 159427,
  "title": "Copy of NN doesn't work as original did",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/159427",
  "author_name": "",
  "post_date": "2020-06-17T12:20:43.244942700Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi,\nI use a copy of public notebook for efficient net.\nThen I do:</p>\n\n<p><code>\ntrain_dataset_1 = get_test_dataset(ordered=True)\ntrain_images_ds = train_dataset_1.map(lambda image, idnum: image)\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\n</code></p>\n\n<p>Now, if I use an original NN (as is copypasted between most of those notebooks), this code works. But if I make a copy:</p>\n\n<p>```\nmodel_reduced_b5_imagenet = tf.keras.Sequential()</p>\n\n<p>for layer in model_b5_imagenet.layers: # [:-2]:\n    model_reduced_b5_imagenet.add(layer)</p>\n\n<p>model_reduced_b5_imagenet.compile(optimizer='adam', \n    loss = 'binary_crossentropy', metrics=['accuracy'])\n```</p>\n\n<p>Then it hungs forever and then dies with \"socket closed\". \nAs far as I can see in summary, networks are of the same structure.</p>\n\n<p>Any suggestions?\nThank you.</p>",
  "messages": [
    {
      "id": "890269",
      "postDate": "06/17/2020 12:20:43",
      "content": "<p>Hi,\nI use a copy of public notebook for efficient net.\nThen I do:</p>\n\n<p><code>\ntrain_dataset_1 = get_test_dataset(ordered=True)\ntrain_images_ds = train_dataset_1.map(lambda image, idnum: image)\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\n</code></p>\n\n<p>Now, if I use an original NN (as is copypasted between most of those notebooks), this code works. But if I make a copy:</p>\n\n<p>```\nmodel_reduced_b5_imagenet = tf.keras.Sequential()</p>\n\n<p>for layer in model_b5_imagenet.layers: # [:-2]:\n    model_reduced_b5_imagenet.add(layer)</p>\n\n<p>model_reduced_b5_imagenet.compile(optimizer='adam', \n    loss = 'binary_crossentropy', metrics=['accuracy'])\n```</p>\n\n<p>Then it hungs forever and then dies with \"socket closed\". \nAs far as I can see in summary, networks are of the same structure.</p>\n\n<p>Any suggestions?\nThank you.</p>",
      "rawMarkdown": "Hi,\nI use a copy of public notebook for efficient net.\nThen I do:\n\n```\ntrain_dataset_1 = get_test_dataset(ordered=True)\ntrain_images_ds = train_dataset_1.map(lambda image, idnum: image)\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\n```\n\nNow, if I use an original NN (as is copypasted between most of those notebooks), this code works. But if I make a copy:\n\n```\nmodel_reduced_b5_imagenet = tf.keras.Sequential()\n\nfor layer in model_b5_imagenet.layers: # [:-2]:\n    model_reduced_b5_imagenet.add(layer)\n    \nmodel_reduced_b5_imagenet.compile(optimizer='adam', \n    loss = 'binary_crossentropy', metrics=['accuracy'])\n```\n\nThen it hungs forever and then dies with \"socket closed\". \nAs far as I can see in summary, networks are of the same structure.\n\nAny suggestions?\nThank you.",
      "votes": null
    },
    {
      "id": "890354",
      "postDate": "06/17/2020 13:13:50",
      "content": "<p>does model_reduced_b5_imagenet refer to model_b5_image_net?</p>\n\n<p>As you add layers to model_reduced_b5_imagenet are they added to model_b5_imagenet also?</p>\n\n<p>Then it would go on forever.</p>\n\n<p>put a print statement in the \"for\" loop to see what is actually happening.</p>",
      "rawMarkdown": "does model_reduced_b5_imagenet refer to model_b5_image_net?\n\nAs you add layers to model_reduced_b5_imagenet are they added to model_b5_imagenet also?\n\nThen it would go on forever.\n\nput a print statement in the \"for\" loop to see what is actually happening.",
      "votes": null
    },
    {
      "id": "890446",
      "postDate": "06/17/2020 14:12:10",
      "content": "<blockquote>\n  <p>does modelreducedb5imagenet refer to modelb5imagenet?\n  No. Originally, I wanted to get a copy of modelb5imagenet, but without the last two layers. This is why it is called modelreducedb5imagenet. Then I encountered a problem, and decided to make a complete copy, for test purposes.\n  The summary shows that models are the same.\n  The \"forever\" happens not in copying the model, but in \n  probabilities = model_reduced_b5_imagenet.predict(train_images_ds)</p>\n</blockquote>\n\n<p>In other words, if I use \nprobabilities = model_b5_imagenet.predict(train_images_ds)\nthen it works. But\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\nhungs.</p>",
      "rawMarkdown": "&gt; does modelreducedb5imagenet refer to modelb5imagenet?\nNo. Originally, I wanted to get a copy of modelb5imagenet, but without the last two layers. This is why it is called modelreducedb5imagenet. Then I encountered a problem, and decided to make a complete copy, for test purposes.\nThe summary shows that models are the same.\nThe \"forever\" happens not in copying the model, but in \nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\n\nIn other words, if I use \nprobabilities = model_b5_imagenet.predict(train_images_ds)\nthen it works. But\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\nhungs.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 890354,
      "author_name": "richardepstein",
      "author_url": "",
      "post_date": "06/17/2020 13:13:50",
      "content": "<p>does model_reduced_b5_imagenet refer to model_b5_image_net?</p>\n\n<p>As you add layers to model_reduced_b5_imagenet are they added to model_b5_imagenet also?</p>\n\n<p>Then it would go on forever.</p>\n\n<p>put a print statement in the \"for\" loop to see what is actually happening.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 890446,
      "author_name": "fizpok",
      "author_url": "",
      "post_date": "06/17/2020 14:12:10",
      "content": "<blockquote>\n  <p>does modelreducedb5imagenet refer to modelb5imagenet?\n  No. Originally, I wanted to get a copy of modelb5imagenet, but without the last two layers. This is why it is called modelreducedb5imagenet. Then I encountered a problem, and decided to make a complete copy, for test purposes.\n  The summary shows that models are the same.\n  The \"forever\" happens not in copying the model, but in \n  probabilities = model_reduced_b5_imagenet.predict(train_images_ds)</p>\n</blockquote>\n\n<p>In other words, if I use \nprobabilities = model_b5_imagenet.predict(train_images_ds)\nthen it works. But\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\nhungs.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "890269": "Hi,\nI use a copy of public notebook for efficient net.\nThen I do:\n\n```\ntrain_dataset_1 = get_test_dataset(ordered=True)\ntrain_images_ds = train_dataset_1.map(lambda image, idnum: image)\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\n```\n\nNow, if I use an original NN (as is copypasted between most of those notebooks), this code works. But if I make a copy:\n\n```\nmodel_reduced_b5_imagenet = tf.keras.Sequential()\n\nfor layer in model_b5_imagenet.layers: # [:-2]:\n    model_reduced_b5_imagenet.add(layer)\n    \nmodel_reduced_b5_imagenet.compile(optimizer='adam', \n    loss = 'binary_crossentropy', metrics=['accuracy'])\n```\n\nThen it hungs forever and then dies with \"socket closed\". \nAs far as I can see in summary, networks are of the same structure.\n\nAny suggestions?\nThank you.",
    "890354": "does model_reduced_b5_imagenet refer to model_b5_image_net?\n\nAs you add layers to model_reduced_b5_imagenet are they added to model_b5_imagenet also?\n\nThen it would go on forever.\n\nput a print statement in the \"for\" loop to see what is actually happening.",
    "890446": "&gt; does modelreducedb5imagenet refer to modelb5imagenet?\nNo. Originally, I wanted to get a copy of modelb5imagenet, but without the last two layers. This is why it is called modelreducedb5imagenet. Then I encountered a problem, and decided to make a complete copy, for test purposes.\nThe summary shows that models are the same.\nThe \"forever\" happens not in copying the model, but in \nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\n\nIn other words, if I use \nprobabilities = model_b5_imagenet.predict(train_images_ds)\nthen it works. But\nprobabilities = model_reduced_b5_imagenet.predict(train_images_ds)\nhungs."
  },
  "source": "meta"
}