{
  "id": 115020,
  "title": "TensorFlow 2.0 versus TensorFlow 1.14",
  "url": "/competitions/understanding_cloud_organization/discussion/115020",
  "author_name": "",
  "post_date": "2019-10-30T19:10:23.087788100Z",
  "votes": 14,
  "comment_count": 13,
  "views": 0,
  "content": "<p>Kaggle recently (October 28, 2019) updated their notebooks to use the new TensorFlow 2.0. Previously notebooks used TF 1.14.0. </p>\n\n<p>If your Keras / TensorFlow notebook is crashing, consider reinstalling the old TensorFlow. I noticed that TF2.0 was using more memory than TF1.14 in one of my notebooks when I ensembled many models. Turning internet on and adding these two lines at the beginning of my kernel, fixed the problem:</p>\n\n<pre><code>!pip install tensorflow-gpu==1.14.0\n!pip install keras==2.2.4\n</code></pre>",
  "messages": [
    {
      "id": "661849",
      "postDate": "10/30/2019 19:10:23",
      "content": "<p>Kaggle recently (October 28, 2019) updated their notebooks to use the new TensorFlow 2.0. Previously notebooks used TF 1.14.0. </p>\n\n<p>If your Keras / TensorFlow notebook is crashing, consider reinstalling the old TensorFlow. I noticed that TF2.0 was using more memory than TF1.14 in one of my notebooks when I ensembled many models. Turning internet on and adding these two lines at the beginning of my kernel, fixed the problem:</p>\n\n<pre><code>!pip install tensorflow-gpu==1.14.0\n!pip install keras==2.2.4\n</code></pre>",
      "rawMarkdown": "Kaggle recently (October 28, 2019) updated their notebooks to use the new TensorFlow 2.0. Previously notebooks used TF 1.14.0. \n\nIf your Keras / TensorFlow notebook is crashing, consider reinstalling the old TensorFlow. I noticed that TF2.0 was using more memory than TF1.14 in one of my notebooks when I ensembled many models. Turning internet on and adding these two lines at the beginning of my kernel, fixed the problem:\n\n    !pip install tensorflow-gpu==1.14.0\n    !pip install keras==2.2.4",
      "votes": null
    },
    {
      "id": "662036",
      "postDate": "10/31/2019 02:36:03",
      "content": "<p>Do I need to first uninstall the new versions or just install directly?</p>",
      "rawMarkdown": "Do I need to first uninstall the new versions or just install directly?",
      "votes": null
    },
    {
      "id": "662037",
      "postDate": "10/31/2019 02:41:24",
      "content": "<p>Just execute those two lines of code as the first 2 lines of code in your notebook. It takes care of uninstallation for you.</p>",
      "rawMarkdown": "Just execute those two lines of code as the first 2 lines of code in your notebook. It takes care of uninstallation for you.",
      "votes": null
    },
    {
      "id": "662107",
      "postDate": "10/31/2019 04:59:01",
      "content": "<p>Also did you check out this <a href=\"https://stackoverflow.com/questions/58441514/why-is-tensorflow-2-much-slower-than-tensorflow-1\">issue</a> in stack overflow ?  Seems TF2 is much slower than TF1\n&gt; Below is code benchmarking performance, TF1 vs. TF2 - with TF1 running anywhere from 47% to 276% faster.</p>\n\n<p><img src=\"https://i.stack.imgur.com/ayBCS.png\" alt=\"\"></p>",
      "rawMarkdown": "Also did you check out this [issue](https://stackoverflow.com/questions/58441514/why-is-tensorflow-2-much-slower-than-tensorflow-1) in stack overflow ?  Seems TF2 is much slower than TF1\n&gt; Below is code benchmarking performance, TF1 vs. TF2 - with TF1 running anywhere from 47% to 276% faster.\n\n![](https://i.stack.imgur.com/ayBCS.png)",
      "votes": null
    },
    {
      "id": "662151",
      "postDate": "10/31/2019 06:24:19",
      "content": "<p>Hi,\nGood point,\n <strong>Disable Tensorflow 2.0 behaviour:</strong>\nAnother simple work-around is to disable the Tensorflow2.0 behaviors using following line of code at the start:</p>\n\n<p><code>import tensorflow.compat.v1 as tf</code>\n<code>tf.disable_v2_behavior()</code></p>",
      "rawMarkdown": "Hi,\nGood point,\n **Disable Tensorflow 2.0 behaviour:**\nAnother simple work-around is to disable the Tensorflow2.0 behaviors using following line of code at the start:\n\n`import tensorflow.compat.v1 as tf`\n`tf.disable_v2_behavior()`",
      "votes": null
    },
    {
      "id": "662211",
      "postDate": "10/31/2019 08:23:08",
      "content": "<p>It's more than likely linked to eager exécution vs graph execution. Did you tried to refactor with tf.function?\n Even pytorch is using torchscipt now  as a tensorflow graph style speedup. There is also xla which copies plaidml compilation</p>",
      "rawMarkdown": "It's more than likely linked to eager exécution vs graph execution. Did you tried to refactor with tf.function?\n Even pytorch is using torchscipt now  as a tensorflow graph style speedup. There is also xla which copies plaidml compilation",
      "votes": null
    },
    {
      "id": "662297",
      "postDate": "10/31/2019 11:49:46",
      "content": "<p>The error occurred just loading models. Each model is 125MB on disk but TF2.0 was using 3.5GB (or so) RAM for each loaded model whereas TF1.14 only uses 400MB (or so) to load each model.</p>\n\n<pre><code>from keras.models import load_model\nmodel1 = load_model('Seg_0.h5')\nmodel2 = load_model('Seg_1.h5')\nmodel3 = load_model('Seg_2.h5')\n</code></pre>",
      "rawMarkdown": "The error occurred just loading models. Each model is 125MB on disk but TF2.0 was using 3.5GB (or so) RAM for each loaded model whereas TF1.14 only uses 400MB (or so) to load each model.\n\n    from keras.models import load_model\n    model1 = load_model('Seg_0.h5')\n    model2 = load_model('Seg_1.h5')\n    model3 = load_model('Seg_2.h5')",
      "votes": null
    },
    {
      "id": "662298",
      "postDate": "10/31/2019 11:50:04",
      "content": "<p>Thanks I wasn't aware of this trick</p>",
      "rawMarkdown": "Thanks I wasn't aware of this trick",
      "votes": null
    },
    {
      "id": "662301",
      "postDate": "10/31/2019 11:53:07",
      "content": "<p>Interesting. I've observed that some segmentation models (and/or backbones) get faster in TF2.0 while others are slower or the same. The biggest issue I'm experiencing is memory use. Just loading saved models uses gigabytes in TF2.0 whereas TF1.14 uses megabytes.</p>",
      "rawMarkdown": "Interesting. I've observed that some segmentation models (and/or backbones) get faster in TF2.0 while others are slower or the same. The biggest issue I'm experiencing is memory use. Just loading saved models uses gigabytes in TF2.0 whereas TF1.14 uses megabytes.",
      "votes": null
    },
    {
      "id": "922456",
      "postDate": "07/10/2020 05:39:19",
      "content": "<p>Hi  Chris,</p>\n\n<p>I did this :</p>\n\n<p><code>\n!pip install tensorflow-gpu==1.14.0\nimport tensorflow \nprint(tensorflow.__version__)\n</code>\nOutput : 2.2.0</p>\n\n<p>Any idea what's wrong ?</p>",
      "rawMarkdown": "Hi  Chris,\n\nI did this :\n\n```\n!pip install tensorflow-gpu==1.14.0\nimport tensorflow \nprint(tensorflow.__version__)\n```\nOutput : 2.2.0\n\nAny idea what's wrong ?",
      "votes": null
    },
    {
      "id": "1007740",
      "postDate": "09/12/2020 12:47:23",
      "content": "<p>try to manually remove tf by <code>!pip uninstall -y tensorflow</code> </p>",
      "rawMarkdown": "try to manually remove tf by ` !pip uninstall -y tensorflow`",
      "votes": null
    },
    {
      "id": "1101421",
      "postDate": "12/03/2020 22:19:31",
      "content": "<p>did you find what you were doing wrong? I'm not able to install tensorflow-gpu==1.14.0, tensorflow==1.14.0 works, but the gpu version breaks my kernel.</p>",
      "rawMarkdown": "did you find what you were doing wrong? I'm not able to install tensorflow-gpu==1.14.0, tensorflow==1.14.0 works, but the gpu version breaks my kernel.",
      "votes": null
    },
    {
      "id": "1101529",
      "postDate": "12/04/2020 01:41:50",
      "content": "<p>Why not, it is working ! after <code>!pip uninstall -y tensorflow</code> only do <code>!pip install tensorflow-gpu==1.14.0</code> thats all. GPU and Internet must be turned on ofcourse.<br>\nIf not working check whether it is installed with pip or conda: <br>\nsearch with: <code>conda search &lt;name&gt;</code>(or conda list) or <code>pip search &lt;package-name&gt;</code><br>\nremove with: <code>pip uninstall &lt;name&gt;</code> or remove with <code>conda remove &lt;name&gt;</code></p>",
      "rawMarkdown": "Why not, it is working ! after `!pip uninstall -y tensorflow` only do `!pip install tensorflow-gpu==1.14.0` thats all. GPU and Internet must be turned on ofcourse.\nIf not working check whether it is installed with pip or conda: \nsearch with: `conda search <name>`(or conda list) or `pip search <package-name>`\nremove with: `pip uninstall <name>` or remove with `conda remove <name>`",
      "votes": null
    },
    {
      "id": "1101791",
      "postDate": "12/04/2020 09:06:21",
      "content": "<p>Import of tensorflow gives me a stack trace with last element:</p>\n<pre><code>ImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model' (/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/saving/saved_model/__init__.py)\n</code></pre>\n<p>Will try with conda and also a new notebook, must be something wrong with some residual installs I suppose. Thanks!</p>",
      "rawMarkdown": "Import of tensorflow gives me a stack trace with last element:\n```\nImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model' (/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/saving/saved_model/__init__.py)\n```\nWill try with conda and also a new notebook, must be something wrong with some residual installs I suppose. Thanks!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 662036,
      "author_name": "gogo827jz",
      "author_url": "",
      "post_date": "10/31/2019 02:36:03",
      "content": "<p>Do I need to first uninstall the new versions or just install directly?</p>",
      "votes": null,
      "replies": [
        {
          "id": 662037,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "10/31/2019 02:41:24",
          "content": "<p>Just execute those two lines of code as the first 2 lines of code in your notebook. It takes care of uninstallation for you.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 662107,
      "author_name": "khairulislam",
      "author_url": "",
      "post_date": "10/31/2019 04:59:01",
      "content": "<p>Also did you check out this <a href=\"https://stackoverflow.com/questions/58441514/why-is-tensorflow-2-much-slower-than-tensorflow-1\">issue</a> in stack overflow ?  Seems TF2 is much slower than TF1\n&gt; Below is code benchmarking performance, TF1 vs. TF2 - with TF1 running anywhere from 47% to 276% faster.</p>\n\n<p><img src=\"https://i.stack.imgur.com/ayBCS.png\" alt=\"\"></p>",
      "votes": null,
      "replies": [
        {
          "id": 662301,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "10/31/2019 11:53:07",
          "content": "<p>Interesting. I've observed that some segmentation models (and/or backbones) get faster in TF2.0 while others are slower or the same. The biggest issue I'm experiencing is memory use. Just loading saved models uses gigabytes in TF2.0 whereas TF1.14 uses megabytes.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 662151,
      "author_name": "chandraroy",
      "author_url": "",
      "post_date": "10/31/2019 06:24:19",
      "content": "<p>Hi,\nGood point,\n <strong>Disable Tensorflow 2.0 behaviour:</strong>\nAnother simple work-around is to disable the Tensorflow2.0 behaviors using following line of code at the start:</p>\n\n<p><code>import tensorflow.compat.v1 as tf</code>\n<code>tf.disable_v2_behavior()</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 662298,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "10/31/2019 11:50:04",
          "content": "<p>Thanks I wasn't aware of this trick</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 662211,
      "author_name": "cedriclacrambe",
      "author_url": "",
      "post_date": "10/31/2019 08:23:08",
      "content": "<p>It's more than likely linked to eager exécution vs graph execution. Did you tried to refactor with tf.function?\n Even pytorch is using torchscipt now  as a tensorflow graph style speedup. There is also xla which copies plaidml compilation</p>",
      "votes": null,
      "replies": [
        {
          "id": 662297,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "10/31/2019 11:49:46",
          "content": "<p>The error occurred just loading models. Each model is 125MB on disk but TF2.0 was using 3.5GB (or so) RAM for each loaded model whereas TF1.14 only uses 400MB (or so) to load each model.</p>\n\n<pre><code>from keras.models import load_model\nmodel1 = load_model('Seg_0.h5')\nmodel2 = load_model('Seg_1.h5')\nmodel3 = load_model('Seg_2.h5')\n</code></pre>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 922456,
      "author_name": "ahmedf",
      "author_url": "",
      "post_date": "07/10/2020 05:39:19",
      "content": "<p>Hi  Chris,</p>\n\n<p>I did this :</p>\n\n<p><code>\n!pip install tensorflow-gpu==1.14.0\nimport tensorflow \nprint(tensorflow.__version__)\n</code>\nOutput : 2.2.0</p>\n\n<p>Any idea what's wrong ?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1007740,
          "author_name": "anku5hk",
          "author_url": "",
          "post_date": "09/12/2020 12:47:23",
          "content": "<p>try to manually remove tf by <code>!pip uninstall -y tensorflow</code> </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1101421,
          "author_name": "bouweceunen",
          "author_url": "",
          "post_date": "12/03/2020 22:19:31",
          "content": "<p>did you find what you were doing wrong? I'm not able to install tensorflow-gpu==1.14.0, tensorflow==1.14.0 works, but the gpu version breaks my kernel.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1101529,
          "author_name": "anku5hk",
          "author_url": "",
          "post_date": "12/04/2020 01:41:50",
          "content": "<p>Why not, it is working ! after <code>!pip uninstall -y tensorflow</code> only do <code>!pip install tensorflow-gpu==1.14.0</code> thats all. GPU and Internet must be turned on ofcourse.<br>\nIf not working check whether it is installed with pip or conda: <br>\nsearch with: <code>conda search &lt;name&gt;</code>(or conda list) or <code>pip search &lt;package-name&gt;</code><br>\nremove with: <code>pip uninstall &lt;name&gt;</code> or remove with <code>conda remove &lt;name&gt;</code></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1101791,
          "author_name": "bouweceunen",
          "author_url": "",
          "post_date": "12/04/2020 09:06:21",
          "content": "<p>Import of tensorflow gives me a stack trace with last element:</p>\n<pre><code>ImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model' (/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/saving/saved_model/__init__.py)\n</code></pre>\n<p>Will try with conda and also a new notebook, must be something wrong with some residual installs I suppose. Thanks!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "661849": "Kaggle recently (October 28, 2019) updated their notebooks to use the new TensorFlow 2.0. Previously notebooks used TF 1.14.0. \n\nIf your Keras / TensorFlow notebook is crashing, consider reinstalling the old TensorFlow. I noticed that TF2.0 was using more memory than TF1.14 in one of my notebooks when I ensembled many models. Turning internet on and adding these two lines at the beginning of my kernel, fixed the problem:\n\n    !pip install tensorflow-gpu==1.14.0\n    !pip install keras==2.2.4",
    "662036": "Do I need to first uninstall the new versions or just install directly?",
    "662037": "Just execute those two lines of code as the first 2 lines of code in your notebook. It takes care of uninstallation for you.",
    "662107": "Also did you check out this [issue](https://stackoverflow.com/questions/58441514/why-is-tensorflow-2-much-slower-than-tensorflow-1) in stack overflow ?  Seems TF2 is much slower than TF1\n&gt; Below is code benchmarking performance, TF1 vs. TF2 - with TF1 running anywhere from 47% to 276% faster.\n\n![](https://i.stack.imgur.com/ayBCS.png)",
    "662151": "Hi,\nGood point,\n **Disable Tensorflow 2.0 behaviour:**\nAnother simple work-around is to disable the Tensorflow2.0 behaviors using following line of code at the start:\n\n`import tensorflow.compat.v1 as tf`\n`tf.disable_v2_behavior()`",
    "662211": "It's more than likely linked to eager exécution vs graph execution. Did you tried to refactor with tf.function?\n Even pytorch is using torchscipt now  as a tensorflow graph style speedup. There is also xla which copies plaidml compilation",
    "662297": "The error occurred just loading models. Each model is 125MB on disk but TF2.0 was using 3.5GB (or so) RAM for each loaded model whereas TF1.14 only uses 400MB (or so) to load each model.\n\n    from keras.models import load_model\n    model1 = load_model('Seg_0.h5')\n    model2 = load_model('Seg_1.h5')\n    model3 = load_model('Seg_2.h5')",
    "662298": "Thanks I wasn't aware of this trick",
    "662301": "Interesting. I've observed that some segmentation models (and/or backbones) get faster in TF2.0 while others are slower or the same. The biggest issue I'm experiencing is memory use. Just loading saved models uses gigabytes in TF2.0 whereas TF1.14 uses megabytes.",
    "922456": "Hi  Chris,\n\nI did this :\n\n```\n!pip install tensorflow-gpu==1.14.0\nimport tensorflow \nprint(tensorflow.__version__)\n```\nOutput : 2.2.0\n\nAny idea what's wrong ?",
    "1007740": "try to manually remove tf by ` !pip uninstall -y tensorflow`",
    "1101421": "did you find what you were doing wrong? I'm not able to install tensorflow-gpu==1.14.0, tensorflow==1.14.0 works, but the gpu version breaks my kernel.",
    "1101529": "Why not, it is working ! after `!pip uninstall -y tensorflow` only do `!pip install tensorflow-gpu==1.14.0` thats all. GPU and Internet must be turned on ofcourse.\nIf not working check whether it is installed with pip or conda: \nsearch with: `conda search <name>`(or conda list) or `pip search <package-name>`\nremove with: `pip uninstall <name>` or remove with `conda remove <name>`",
    "1101791": "Import of tensorflow gives me a stack trace with last element:\n```\nImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model' (/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/saving/saved_model/__init__.py)\n```\nWill try with conda and also a new notebook, must be something wrong with some residual installs I suppose. Thanks!"
  },
  "source": "meta"
}