{
  "id": 169262,
  "title": "Something wrong with strategy ? ",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/169262",
  "author_name": "",
  "post_date": "2020-07-23T11:25:43.987490100Z",
  "votes": null,
  "comment_count": 6,
  "views": 0,
  "content": "<p>I have set mirrored strategy and constructed a sample model </p>\n\n<p>with strategy.scope():</p>\n\n<p>bias = tf.keras.initializers.Constant(bias)</p>\n\n<p>base_model = tf.keras.applications.ResNet50(input_shape = (SHAPE[0], SHAPE[1], 3), include_top = False,\n                                               weights = \"imagenet\")</p>\n\n<p>base_model.trainable = False</p>\n\n<p>model = tf.keras.Sequential([base_model,\n                                 tf.keras.layers.GlobalAveragePooling2D(),\n                                 tf.keras.layers.Dense(20, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.4),\n                                 tf.keras.layers.Dense(10, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.3),\n                                 tf.keras.layers.Dense(1, activation = \"sigmoid\", bias_initializer = bias) <br>\n                                ])</p>\n\n<p>model.compile(optimizer = \"adam\", loss = \"binary_crossentropy\", metrics = </p>\n\n<p>tf.keras.metrics.AUC(name = 'auc'))</p>\n\n<p>However, when I fit my model I always get : </p>\n\n<p><strong>'NoneType' object has no attribute 'set_model'</strong></p>\n\n<p><strong>WHAT'S GOING WRONG?</strong></p>\n\n<p>If someone knows, please do reply!</p>",
  "messages": [
    {
      "id": "941721",
      "postDate": "07/23/2020 11:25:43",
      "content": "<p>I have set mirrored strategy and constructed a sample model </p>\n\n<p>with strategy.scope():</p>\n\n<p>bias = tf.keras.initializers.Constant(bias)</p>\n\n<p>base_model = tf.keras.applications.ResNet50(input_shape = (SHAPE[0], SHAPE[1], 3), include_top = False,\n                                               weights = \"imagenet\")</p>\n\n<p>base_model.trainable = False</p>\n\n<p>model = tf.keras.Sequential([base_model,\n                                 tf.keras.layers.GlobalAveragePooling2D(),\n                                 tf.keras.layers.Dense(20, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.4),\n                                 tf.keras.layers.Dense(10, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.3),\n                                 tf.keras.layers.Dense(1, activation = \"sigmoid\", bias_initializer = bias) <br>\n                                ])</p>\n\n<p>model.compile(optimizer = \"adam\", loss = \"binary_crossentropy\", metrics = </p>\n\n<p>tf.keras.metrics.AUC(name = 'auc'))</p>\n\n<p>However, when I fit my model I always get : </p>\n\n<p><strong>'NoneType' object has no attribute 'set_model'</strong></p>\n\n<p><strong>WHAT'S GOING WRONG?</strong></p>\n\n<p>If someone knows, please do reply!</p>",
      "rawMarkdown": "I have set mirrored strategy and constructed a sample model \n\nwith strategy.scope():\n    \nbias = tf.keras.initializers.Constant(bias)\n    \nbase_model = tf.keras.applications.ResNet50(input_shape = (SHAPE[0], SHAPE[1], 3), include_top = False,\n                                               weights = \"imagenet\")\n    \nbase_model.trainable = False\n    \nmodel = tf.keras.Sequential([base_model,\n                                 tf.keras.layers.GlobalAveragePooling2D(),\n                                 tf.keras.layers.Dense(20, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.4),\n                                 tf.keras.layers.Dense(10, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.3),\n                                 tf.keras.layers.Dense(1, activation = \"sigmoid\", bias_initializer = bias)                                     \n                                ])\n    \nmodel.compile(optimizer = \"adam\", loss = \"binary_crossentropy\", metrics = \n\ntf.keras.metrics.AUC(name = 'auc'))\n\n\nHowever, when I fit my model I always get : \n\n**'NoneType' object has no attribute 'set_model'**\n\n\n**WHAT'S GOING WRONG?**\n\nIf someone knows, please do reply!",
      "votes": null
    },
    {
      "id": "942074",
      "postDate": "07/23/2020 15:08:53",
      "content": "<p>It might just be a typo on the screen but you have both:</p>\n\n<p>basemodel\nbase_model</p>\n\n<p>-Rich</p>",
      "rawMarkdown": "It might just be a typo on the screen but you have both:\n\nbasemodel\nbase_model\n\n-Rich",
      "votes": null
    },
    {
      "id": "942233",
      "postDate": "07/23/2020 16:45:50",
      "content": "<p>Yes, it's a typo! Please assume it to be base_model.</p>",
      "rawMarkdown": "Yes, it's a typo! Please assume it to be base_model.",
      "votes": null
    },
    {
      "id": "942635",
      "postDate": "07/23/2020 22:25:12",
      "content": "<p>It was a bit of learning for my first time use of tf 2 on dual GPU - pretty sure I had similiar error but that several weeks ago.</p>\n\n<p>Just starting to compare my kernels to your bit of code.  I am starting with the assumption that you do have more than one GPU on you PC  and that you have code that validates all GPU's being seen?</p>\n\n<p>Also assume that in earlier code you calculate a bias?  Your code bit should error out if you did not, but not sure it errors out if not correct dtype.</p>\n\n<p>After you compile can you print a model.summary()  ?</p>\n\n<p>After you complie and generate a summary can you plot the graph\n<code>tf.keras.utils.plot_model(model, \"multi_input_and_output_model.png\", show_shapes=True)</code></p>\n\n<p>If it does not share any secret sauce can you share the plot?</p>",
      "rawMarkdown": "It was a bit of learning for my first time use of tf 2 on dual GPU - pretty sure I had similiar error but that several weeks ago.\n\nJust starting to compare my kernels to your bit of code.  I am starting with the assumption that you do have more than one GPU on you PC  and that you have code that validates all GPU's being seen?\n\nAlso assume that in earlier code you calculate a bias?  Your code bit should error out if you did not, but not sure it errors out if not correct dtype.\n\nAfter you compile can you print a model.summary()  ?\n\nAfter you complie and generate a summary can you plot the graph\n`tf.keras.utils.plot_model(model, \"multi_input_and_output_model.png\", show_shapes=True)`\n\nIf it does not share any secret sauce can you share the plot?",
      "votes": null
    },
    {
      "id": "942639",
      "postDate": "07/23/2020 22:29:30",
      "content": "<p>You don't show the fit code but tf.keras.callbacks.Callback has a set_model method.  Can you share your callbacks?</p>",
      "rawMarkdown": "You don't show the fit code but tf.keras.callbacks.Callback has a set_model method.  Can you share your callbacks?",
      "votes": null
    },
    {
      "id": "942663",
      "postDate": "07/23/2020 23:17:15",
      "content": "<p>Because Kaggle does a poor job of letting you copy and paste I was not successful in copy and pasting the above into my base model and running it.  Lots of characters go bad on kaggle (for example the underscore in base_model goes away when you paste).</p>\n\n<p>Will try again after I hear from you on a couple of my questions already asked.</p>",
      "rawMarkdown": "Because Kaggle does a poor job of letting you copy and paste I was not successful in copy and pasting the above into my base model and running it.  Lots of characters go bad on kaggle (for example the underscore in base_model goes away when you paste).\n\nWill try again after I hear from you on a couple of my questions already asked.",
      "votes": null
    },
    {
      "id": "946038",
      "postDate": "07/26/2020 09:56:49",
      "content": "<p>Yes!! I removed LRScheduler from callbacks and used LRReduceOnPlateau callback. This solved the problem somehow!!</p>",
      "rawMarkdown": "Yes!! I removed LRScheduler from callbacks and used LRReduceOnPlateau callback. This solved the problem somehow!!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 942074,
      "author_name": "richardepstein",
      "author_url": "",
      "post_date": "07/23/2020 15:08:53",
      "content": "<p>It might just be a typo on the screen but you have both:</p>\n\n<p>basemodel\nbase_model</p>\n\n<p>-Rich</p>",
      "votes": null,
      "replies": [
        {
          "id": 942233,
          "author_name": "fireheart7",
          "author_url": "",
          "post_date": "07/23/2020 16:45:50",
          "content": "<p>Yes, it's a typo! Please assume it to be base_model.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 942635,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "07/23/2020 22:25:12",
      "content": "<p>It was a bit of learning for my first time use of tf 2 on dual GPU - pretty sure I had similiar error but that several weeks ago.</p>\n\n<p>Just starting to compare my kernels to your bit of code.  I am starting with the assumption that you do have more than one GPU on you PC  and that you have code that validates all GPU's being seen?</p>\n\n<p>Also assume that in earlier code you calculate a bias?  Your code bit should error out if you did not, but not sure it errors out if not correct dtype.</p>\n\n<p>After you compile can you print a model.summary()  ?</p>\n\n<p>After you complie and generate a summary can you plot the graph\n<code>tf.keras.utils.plot_model(model, \"multi_input_and_output_model.png\", show_shapes=True)</code></p>\n\n<p>If it does not share any secret sauce can you share the plot?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 942639,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "07/23/2020 22:29:30",
      "content": "<p>You don't show the fit code but tf.keras.callbacks.Callback has a set_model method.  Can you share your callbacks?</p>",
      "votes": null,
      "replies": [
        {
          "id": 946038,
          "author_name": "fireheart7",
          "author_url": "",
          "post_date": "07/26/2020 09:56:49",
          "content": "<p>Yes!! I removed LRScheduler from callbacks and used LRReduceOnPlateau callback. This solved the problem somehow!!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 942663,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "07/23/2020 23:17:15",
      "content": "<p>Because Kaggle does a poor job of letting you copy and paste I was not successful in copy and pasting the above into my base model and running it.  Lots of characters go bad on kaggle (for example the underscore in base_model goes away when you paste).</p>\n\n<p>Will try again after I hear from you on a couple of my questions already asked.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "941721": "I have set mirrored strategy and constructed a sample model \n\nwith strategy.scope():\n    \nbias = tf.keras.initializers.Constant(bias)\n    \nbase_model = tf.keras.applications.ResNet50(input_shape = (SHAPE[0], SHAPE[1], 3), include_top = False,\n                                               weights = \"imagenet\")\n    \nbase_model.trainable = False\n    \nmodel = tf.keras.Sequential([base_model,\n                                 tf.keras.layers.GlobalAveragePooling2D(),\n                                 tf.keras.layers.Dense(20, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.4),\n                                 tf.keras.layers.Dense(10, activation = \"relu\"),\n                                 tf.keras.layers.Dropout(0.3),\n                                 tf.keras.layers.Dense(1, activation = \"sigmoid\", bias_initializer = bias)                                     \n                                ])\n    \nmodel.compile(optimizer = \"adam\", loss = \"binary_crossentropy\", metrics = \n\ntf.keras.metrics.AUC(name = 'auc'))\n\n\nHowever, when I fit my model I always get : \n\n**'NoneType' object has no attribute 'set_model'**\n\n\n**WHAT'S GOING WRONG?**\n\nIf someone knows, please do reply!",
    "942074": "It might just be a typo on the screen but you have both:\n\nbasemodel\nbase_model\n\n-Rich",
    "942233": "Yes, it's a typo! Please assume it to be base_model.",
    "942635": "It was a bit of learning for my first time use of tf 2 on dual GPU - pretty sure I had similiar error but that several weeks ago.\n\nJust starting to compare my kernels to your bit of code.  I am starting with the assumption that you do have more than one GPU on you PC  and that you have code that validates all GPU's being seen?\n\nAlso assume that in earlier code you calculate a bias?  Your code bit should error out if you did not, but not sure it errors out if not correct dtype.\n\nAfter you compile can you print a model.summary()  ?\n\nAfter you complie and generate a summary can you plot the graph\n`tf.keras.utils.plot_model(model, \"multi_input_and_output_model.png\", show_shapes=True)`\n\nIf it does not share any secret sauce can you share the plot?",
    "942639": "You don't show the fit code but tf.keras.callbacks.Callback has a set_model method.  Can you share your callbacks?",
    "942663": "Because Kaggle does a poor job of letting you copy and paste I was not successful in copy and pasting the above into my base model and running it.  Lots of characters go bad on kaggle (for example the underscore in base_model goes away when you paste).\n\nWill try again after I hear from you on a couple of my questions already asked.",
    "946038": "Yes!! I removed LRScheduler from callbacks and used LRReduceOnPlateau callback. This solved the problem somehow!!"
  },
  "source": "meta"
}