{
  "id": 166571,
  "title": "GPU is not working",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/166571",
  "author_name": "",
  "post_date": "2020-07-13T11:09:12.196112200Z",
  "votes": 1,
  "comment_count": 9,
  "views": 0,
  "content": "<p>Hi. I am trying a simple model with GPU. But for some reasons the gpu has 0 utilisation and the learning time is almost the same with and without GPU.</p>\n\n<p>Because I can't get the code formated properly: <a href=\"https://pastebin.com/UqYCWN04\">https://pastebin.com/UqYCWN04</a></p>\n\n<p>```</p>\n\n<h1>This Python 3 environment comes with many helpful analytics libraries installed</h1>\n\n<h1>It is defined by the kaggle/python Docker image: <a href=\"https://github.com/kaggle/docker-python\">https://github.com/kaggle/docker-python</a></h1>\n\n<h1>For example, here's several helpful packages to load</h1>\n\n<p>import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)</p>\n\n<h1>Input data files are available in the read-only \"../input/\" directory</h1>\n\n<h1>For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory</h1>\n\n<p>import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))</p>\n\n<h1>You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save &amp; Run All\"</h1>\n\n<h1>You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session</h1>\n\n<p>import tensorflow as tf\ntf.test.gpu_device_name()</p>\n\n<p>gpus = tf.config.experimental.list_physical_devices('GPU')\nnum_gpus = len(gpus)\nif gpus:\n    try:\n        for gpu in gpus:\n            tf.config.experimental.set_memory_growth(gpu, True)\n        logical_gpus = tf.config.experimental.list_logical_devices('GPU')\n        print(num_gpus, \"Physical GPUs,\", len(logical_gpus), \"Logical GPUs\")\n    except RuntimeError as e:\n        print(e)</p>\n\n<p>#</p>\n\n<h1>Constant Vallues</h1>\n\n<p>train_image_dir = \"../input/siim-isic-melanoma-classification/jpeg/train\"\ntrain_csv = \"../input/siim-isic-melanoma-classification/train.csv\"\nbatch_size = 100</p>\n\n<h1>Have to append .jpg to the image name</h1>\n\n<p>def append_ext(fn):\n    return fn+\".jpg\"</p>\n\n<p>df = pd.read_csv(train_csv)</p>\n\n<p>df['image_name'] = df['image_name'].apply(append_ext)</p>\n\n<h1>Convert strings into categories</h1>\n\n<p>features = [\"diagnosis\"]\ndf2 = pd.get_dummies(df[features])\ndf2['image_name'] = df['image_name']</p>\n\n<p>df2.head()</p>\n\n<h1>Creating Train Dataset</h1>\n\n<p>train_loader = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)</p>\n\n<h1>train_ds = train_loader.flow_from_directory(data_dir, target_size = (32,32) )</h1>\n\n<h1>columns = [\"sex\",\"age_approx\",\"anatom_site_general_challenge\",\"diagnosis\",\"benign_malignant\",\"target\"]</h1>\n\n<p>results = [\"diagnosis_melanoma\"]</p>\n\n<p>train_ds = train_loader.flow_from_dataframe(\ndataframe=df2[:1000],\ndirectory=train_image_dir,\nx_col=\"image_name\",\ny_col=\"diagnosis_melanoma\",\nbatch_size=128,\nseed=42,\nshuffle=True,\nclass_mode=\"raw\",\ntarget_size=(32,32)\n)</p>\n\n<p>model = tf.keras.Sequential()</p>\n\n<p>model.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\", input_shape = [32,32,3]))\nmodel.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(units=128, activation='relu'))\nmodel.add(tf.keras.layers.Dense(units=1, activation='softmax'))\nmodel.compile(optimizer = \"adam\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])\nmodel.summary()</p>\n\n<h1>Alternative model</h1>\n\n<h1>known_model = tf.keras.applications.InceptionResNetV2(include_top = False,weights='imagenet',input_shape=(75,75,3),classes=2, classifier_activation='softmax')</h1>\n\n<h1>known_model.compile(optimizer = \"rmsprop\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])</h1>\n\n<h1>known_model.summary()</h1>\n\n<p>STEP_SIZE_TRAIN=train_ds.n</p>\n\n<h1>train_ds = tf.convert_to_tensor(</h1>\n\n<h1>train_ds, dtype=None, dtype_hint=None, name=None</h1>\n\n<h1>)</h1>\n\n<p>model.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)</p>\n\n<h1>known_model.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)</h1>\n\n<p>```</p>",
  "messages": [
    {
      "id": "927407",
      "postDate": "07/13/2020 11:09:12",
      "content": "<p>Hi. I am trying a simple model with GPU. But for some reasons the gpu has 0 utilisation and the learning time is almost the same with and without GPU.</p>\n\n<p>Because I can't get the code formated properly: <a href=\"https://pastebin.com/UqYCWN04\">https://pastebin.com/UqYCWN04</a></p>\n\n<p>```</p>\n\n<h1>This Python 3 environment comes with many helpful analytics libraries installed</h1>\n\n<h1>It is defined by the kaggle/python Docker image: <a href=\"https://github.com/kaggle/docker-python\">https://github.com/kaggle/docker-python</a></h1>\n\n<h1>For example, here's several helpful packages to load</h1>\n\n<p>import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)</p>\n\n<h1>Input data files are available in the read-only \"../input/\" directory</h1>\n\n<h1>For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory</h1>\n\n<p>import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))</p>\n\n<h1>You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save &amp; Run All\"</h1>\n\n<h1>You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session</h1>\n\n<p>import tensorflow as tf\ntf.test.gpu_device_name()</p>\n\n<p>gpus = tf.config.experimental.list_physical_devices('GPU')\nnum_gpus = len(gpus)\nif gpus:\n    try:\n        for gpu in gpus:\n            tf.config.experimental.set_memory_growth(gpu, True)\n        logical_gpus = tf.config.experimental.list_logical_devices('GPU')\n        print(num_gpus, \"Physical GPUs,\", len(logical_gpus), \"Logical GPUs\")\n    except RuntimeError as e:\n        print(e)</p>\n\n<p>#</p>\n\n<h1>Constant Vallues</h1>\n\n<p>train_image_dir = \"../input/siim-isic-melanoma-classification/jpeg/train\"\ntrain_csv = \"../input/siim-isic-melanoma-classification/train.csv\"\nbatch_size = 100</p>\n\n<h1>Have to append .jpg to the image name</h1>\n\n<p>def append_ext(fn):\n    return fn+\".jpg\"</p>\n\n<p>df = pd.read_csv(train_csv)</p>\n\n<p>df['image_name'] = df['image_name'].apply(append_ext)</p>\n\n<h1>Convert strings into categories</h1>\n\n<p>features = [\"diagnosis\"]\ndf2 = pd.get_dummies(df[features])\ndf2['image_name'] = df['image_name']</p>\n\n<p>df2.head()</p>\n\n<h1>Creating Train Dataset</h1>\n\n<p>train_loader = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)</p>\n\n<h1>train_ds = train_loader.flow_from_directory(data_dir, target_size = (32,32) )</h1>\n\n<h1>columns = [\"sex\",\"age_approx\",\"anatom_site_general_challenge\",\"diagnosis\",\"benign_malignant\",\"target\"]</h1>\n\n<p>results = [\"diagnosis_melanoma\"]</p>\n\n<p>train_ds = train_loader.flow_from_dataframe(\ndataframe=df2[:1000],\ndirectory=train_image_dir,\nx_col=\"image_name\",\ny_col=\"diagnosis_melanoma\",\nbatch_size=128,\nseed=42,\nshuffle=True,\nclass_mode=\"raw\",\ntarget_size=(32,32)\n)</p>\n\n<p>model = tf.keras.Sequential()</p>\n\n<p>model.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\", input_shape = [32,32,3]))\nmodel.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(units=128, activation='relu'))\nmodel.add(tf.keras.layers.Dense(units=1, activation='softmax'))\nmodel.compile(optimizer = \"adam\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])\nmodel.summary()</p>\n\n<h1>Alternative model</h1>\n\n<h1>known_model = tf.keras.applications.InceptionResNetV2(include_top = False,weights='imagenet',input_shape=(75,75,3),classes=2, classifier_activation='softmax')</h1>\n\n<h1>known_model.compile(optimizer = \"rmsprop\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])</h1>\n\n<h1>known_model.summary()</h1>\n\n<p>STEP_SIZE_TRAIN=train_ds.n</p>\n\n<h1>train_ds = tf.convert_to_tensor(</h1>\n\n<h1>train_ds, dtype=None, dtype_hint=None, name=None</h1>\n\n<h1>)</h1>\n\n<p>model.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)</p>\n\n<h1>known_model.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)</h1>\n\n<p>```</p>",
      "rawMarkdown": "Hi. I am trying a simple model with GPU. But for some reasons the gpu has 0 utilisation and the learning time is almost the same with and without GPU.\n\nBecause I can't get the code formated properly: https://pastebin.com/UqYCWN04\n\n```\n# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n        \n\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save &amp; Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n\nimport tensorflow as tf\ntf.test.gpu_device_name()\n\n\ngpus = tf.config.experimental.list_physical_devices('GPU')\nnum_gpus = len(gpus)\nif gpus:\n    try:\n        for gpu in gpus:\n            tf.config.experimental.set_memory_growth(gpu, True)\n        logical_gpus = tf.config.experimental.list_logical_devices('GPU')\n        print(num_gpus, \"Physical GPUs,\", len(logical_gpus), \"Logical GPUs\")\n    except RuntimeError as e:\n        print(e)\n        \n\n#\n#Constant Vallues\n\ntrain_image_dir = \"../input/siim-isic-melanoma-classification/jpeg/train\"\ntrain_csv = \"../input/siim-isic-melanoma-classification/train.csv\"\nbatch_size = 100\n#Have to append .jpg to the image name\ndef append_ext(fn):\n    return fn+\".jpg\"\n\n\ndf = pd.read_csv(train_csv)\n\ndf['image_name'] = df['image_name'].apply(append_ext)\n\n#Convert strings into categories\nfeatures = [\"diagnosis\"]\ndf2 = pd.get_dummies(df[features])\ndf2['image_name'] = df['image_name']\n\ndf2.head()\n\n#Creating Train Dataset\ntrain_loader = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)\n#train_ds = train_loader.flow_from_directory(data_dir, target_size = (32,32) )\n\n#columns = [\"sex\",\"age_approx\",\"anatom_site_general_challenge\",\"diagnosis\",\"benign_malignant\",\"target\"]\nresults = [\"diagnosis_melanoma\"]\n\ntrain_ds = train_loader.flow_from_dataframe(\ndataframe=df2[:1000],\ndirectory=train_image_dir,\nx_col=\"image_name\",\ny_col=\"diagnosis_melanoma\",\nbatch_size=128,\nseed=42,\nshuffle=True,\nclass_mode=\"raw\",\ntarget_size=(32,32)\n)\n\n\nmodel = tf.keras.Sequential()\n\nmodel.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\", input_shape = [32,32,3]))\nmodel.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(units=128, activation='relu'))\nmodel.add(tf.keras.layers.Dense(units=1, activation='softmax'))\nmodel.compile(optimizer = \"adam\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])\nmodel.summary()\n\n\n#Alternative model\n\n#known_model = tf.keras.applications.InceptionResNetV2(include_top = False,weights='imagenet',input_shape=(75,75,3),classes=2, classifier_activation='softmax')\n#known_model.compile(optimizer = \"rmsprop\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])\n#known_model.summary()\n\n\nSTEP_SIZE_TRAIN=train_ds.n\n\n#train_ds = tf.convert_to_tensor(\n#    train_ds, dtype=None, dtype_hint=None, name=None\n#)\n\nmodel.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)\n\n#known_model.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)\n```",
      "votes": null
    },
    {
      "id": "927564",
      "postDate": "07/13/2020 13:36:12",
      "content": "<p>Do you turn it on?</p>",
      "rawMarkdown": "Do you turn it on?",
      "votes": null
    },
    {
      "id": "928258",
      "postDate": "07/13/2020 20:22:11",
      "content": "<p>Yes of course.</p>",
      "rawMarkdown": "Yes of course.",
      "votes": null
    },
    {
      "id": "929224",
      "postDate": "07/14/2020 14:41:16",
      "content": "<p>First see whether you turned it on and then during model fitting, use the wrapper 💯 </p>\n\n<p>with tf.device(\"/device:GPU:0\"):\n        your model.fit statement</p>",
      "rawMarkdown": "First see whether you turned it on and then during model fitting, use the wrapper 💯 \n\nwith tf.device(\"/device:GPU:0\"):\n        your model.fit statement",
      "votes": null
    },
    {
      "id": "929337",
      "postDate": "07/14/2020 15:55:16",
      "content": "<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4684739%2F2fb35e21a54ddaaefe5d773257d554b6%2FAnmerkung%202020-07-14%20175430.png?generation=1594742083733169&amp;alt=media\" alt=\"\"></p>\n\n<p>My script is working in Colab but not in kaggle</p>",
      "rawMarkdown": "![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4684739%2F2fb35e21a54ddaaefe5d773257d554b6%2FAnmerkung%202020-07-14%20175430.png?generation=1594742083733169&amp;alt=media)\n\n\nMy script is working in Colab but not in kaggle",
      "votes": null
    },
    {
      "id": "934123",
      "postDate": "07/18/2020 08:47:12",
      "content": "<p>same issue, I don't know what to do, also I can't use colab because of the limited storage in colab gpu session </p>",
      "rawMarkdown": "same issue, I don't know what to do, also I can't use colab because of the limited storage in colab gpu session",
      "votes": null
    },
    {
      "id": "934275",
      "postDate": "07/18/2020 10:54:17",
      "content": "<p>Working doesn't necessarily means that it is utilizing GPU in colab as well. Use the wrapper I mentioned on both kaggle and colab. </p>",
      "rawMarkdown": "Working doesn't necessarily means that it is utilizing GPU in colab as well. Use the wrapper I mentioned on both kaggle and colab.",
      "votes": null
    },
    {
      "id": "935491",
      "postDate": "07/19/2020 12:42:03",
      "content": "<p>With working  I mean colab utilize it. In colab it was like 30min in Kaggle 8h+</p>",
      "rawMarkdown": "With working  I mean colab utilize it. In colab it was like 30min in Kaggle 8h+",
      "votes": null
    },
    {
      "id": "936662",
      "postDate": "07/20/2020 12:21:02",
      "content": "<p>i see! Even with this wrapper it's taking 8 hrs?</p>",
      "rawMarkdown": "i see! Even with this wrapper it's taking 8 hrs?",
      "votes": null
    },
    {
      "id": "942178",
      "postDate": "07/23/2020 16:11:26",
      "content": "<p>Yes with wrapper its 8hrs and more</p>",
      "rawMarkdown": "Yes with wrapper its 8hrs and more",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 927564,
      "author_name": "doanquanvietnamca",
      "author_url": "",
      "post_date": "07/13/2020 13:36:12",
      "content": "<p>Do you turn it on?</p>",
      "votes": null,
      "replies": [
        {
          "id": 928258,
          "author_name": "losspost",
          "author_url": "",
          "post_date": "07/13/2020 20:22:11",
          "content": "<p>Yes of course.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 929224,
      "author_name": "fireheart7",
      "author_url": "",
      "post_date": "07/14/2020 14:41:16",
      "content": "<p>First see whether you turned it on and then during model fitting, use the wrapper 💯 </p>\n\n<p>with tf.device(\"/device:GPU:0\"):\n        your model.fit statement</p>",
      "votes": null,
      "replies": [
        {
          "id": 929337,
          "author_name": "losspost",
          "author_url": "",
          "post_date": "07/14/2020 15:55:16",
          "content": "<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4684739%2F2fb35e21a54ddaaefe5d773257d554b6%2FAnmerkung%202020-07-14%20175430.png?generation=1594742083733169&amp;alt=media\" alt=\"\"></p>\n\n<p>My script is working in Colab but not in kaggle</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 934275,
          "author_name": "fireheart7",
          "author_url": "",
          "post_date": "07/18/2020 10:54:17",
          "content": "<p>Working doesn't necessarily means that it is utilizing GPU in colab as well. Use the wrapper I mentioned on both kaggle and colab. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 935491,
          "author_name": "losspost",
          "author_url": "",
          "post_date": "07/19/2020 12:42:03",
          "content": "<p>With working  I mean colab utilize it. In colab it was like 30min in Kaggle 8h+</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 936662,
          "author_name": "fireheart7",
          "author_url": "",
          "post_date": "07/20/2020 12:21:02",
          "content": "<p>i see! Even with this wrapper it's taking 8 hrs?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 942178,
          "author_name": "losspost",
          "author_url": "",
          "post_date": "07/23/2020 16:11:26",
          "content": "<p>Yes with wrapper its 8hrs and more</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 934123,
      "author_name": "tarikdincer",
      "author_url": "",
      "post_date": "07/18/2020 08:47:12",
      "content": "<p>same issue, I don't know what to do, also I can't use colab because of the limited storage in colab gpu session </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "927407": "Hi. I am trying a simple model with GPU. But for some reasons the gpu has 0 utilisation and the learning time is almost the same with and without GPU.\n\nBecause I can't get the code formated properly: https://pastebin.com/UqYCWN04\n\n```\n# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n        \n\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save &amp; Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n\nimport tensorflow as tf\ntf.test.gpu_device_name()\n\n\ngpus = tf.config.experimental.list_physical_devices('GPU')\nnum_gpus = len(gpus)\nif gpus:\n    try:\n        for gpu in gpus:\n            tf.config.experimental.set_memory_growth(gpu, True)\n        logical_gpus = tf.config.experimental.list_logical_devices('GPU')\n        print(num_gpus, \"Physical GPUs,\", len(logical_gpus), \"Logical GPUs\")\n    except RuntimeError as e:\n        print(e)\n        \n\n#\n#Constant Vallues\n\ntrain_image_dir = \"../input/siim-isic-melanoma-classification/jpeg/train\"\ntrain_csv = \"../input/siim-isic-melanoma-classification/train.csv\"\nbatch_size = 100\n#Have to append .jpg to the image name\ndef append_ext(fn):\n    return fn+\".jpg\"\n\n\ndf = pd.read_csv(train_csv)\n\ndf['image_name'] = df['image_name'].apply(append_ext)\n\n#Convert strings into categories\nfeatures = [\"diagnosis\"]\ndf2 = pd.get_dummies(df[features])\ndf2['image_name'] = df['image_name']\n\ndf2.head()\n\n#Creating Train Dataset\ntrain_loader = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)\n#train_ds = train_loader.flow_from_directory(data_dir, target_size = (32,32) )\n\n#columns = [\"sex\",\"age_approx\",\"anatom_site_general_challenge\",\"diagnosis\",\"benign_malignant\",\"target\"]\nresults = [\"diagnosis_melanoma\"]\n\ntrain_ds = train_loader.flow_from_dataframe(\ndataframe=df2[:1000],\ndirectory=train_image_dir,\nx_col=\"image_name\",\ny_col=\"diagnosis_melanoma\",\nbatch_size=128,\nseed=42,\nshuffle=True,\nclass_mode=\"raw\",\ntarget_size=(32,32)\n)\n\n\nmodel = tf.keras.Sequential()\n\nmodel.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\", input_shape = [32,32,3]))\nmodel.add(tf.keras.layers.Conv2D(filters=32, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.Conv2D(filters=64, kernel_size = 3, padding =\"same\", activation = \"relu\"))\nmodel.add(tf.keras.layers.MaxPool2D(pool_size = 2, strides = 2, padding='valid'))\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(units=128, activation='relu'))\nmodel.add(tf.keras.layers.Dense(units=1, activation='softmax'))\nmodel.compile(optimizer = \"adam\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])\nmodel.summary()\n\n\n#Alternative model\n\n#known_model = tf.keras.applications.InceptionResNetV2(include_top = False,weights='imagenet',input_shape=(75,75,3),classes=2, classifier_activation='softmax')\n#known_model.compile(optimizer = \"rmsprop\",loss=\"BinaryCrossentropy\",metrics=[\"accuracy\"])\n#known_model.summary()\n\n\nSTEP_SIZE_TRAIN=train_ds.n\n\n#train_ds = tf.convert_to_tensor(\n#    train_ds, dtype=None, dtype_hint=None, name=None\n#)\n\nmodel.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)\n\n#known_model.fit_generator(train_ds,steps_per_epoch=STEP_SIZE_TRAIN,epochs=5)\n```",
    "927564": "Do you turn it on?",
    "928258": "Yes of course.",
    "929224": "First see whether you turned it on and then during model fitting, use the wrapper 💯 \n\nwith tf.device(\"/device:GPU:0\"):\n        your model.fit statement",
    "929337": "![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F4684739%2F2fb35e21a54ddaaefe5d773257d554b6%2FAnmerkung%202020-07-14%20175430.png?generation=1594742083733169&amp;alt=media)\n\n\nMy script is working in Colab but not in kaggle",
    "934123": "same issue, I don't know what to do, also I can't use colab because of the limited storage in colab gpu session",
    "934275": "Working doesn't necessarily means that it is utilizing GPU in colab as well. Use the wrapper I mentioned on both kaggle and colab.",
    "935491": "With working  I mean colab utilize it. In colab it was like 30min in Kaggle 8h+",
    "936662": "i see! Even with this wrapper it's taking 8 hrs?",
    "942178": "Yes with wrapper its 8hrs and more"
  },
  "source": "meta"
}