{
  "id": 223047,
  "title": "Notebook Exceeded Allowed Compute",
  "url": "/competitions/hubmap-kidney-segmentation/discussion/223047",
  "author_name": "",
  "post_date": "2021-03-02T09:05:21.566136400Z",
  "votes": 3,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I can run the public test successfully in my kernel，but encountered Notebook Exceeded Allowed Compute every time I submit, can somebody tell me what the problem is?</p>",
  "messages": [
    {
      "id": "1222894",
      "postDate": "03/02/2021 09:05:21",
      "content": "<p>I can run the public test successfully in my kernel，but encountered Notebook Exceeded Allowed Compute every time I submit, can somebody tell me what the problem is?</p>",
      "rawMarkdown": "I can run the public test successfully in my kernel，but encountered Notebook Exceeded Allowed Compute every time I submit, can somebody tell me what the problem is?",
      "votes": null
    },
    {
      "id": "1224688",
      "postDate": "03/03/2021 01:29:03",
      "content": "<p>it is a memory problem. <br>\nso keep deleting in your code like this </p>\n<pre><code>del train\ndel train_images\ndel test_images\n</code></pre>\n<p>This trick will clear all  allocated memory in GPU</p>\n<p>\"https://www.kaggle.com/titericz/baseline-transfer-learning-randomforest-gpu\"</p>\n<pre><code>from numba import cuda\ncuda.select_device(0)\ncuda.close()\ncuda.select_device(0)\n</code></pre>\n<p>and of course, decrease the <code>batch_size</code></p>",
      "rawMarkdown": "it is a memory problem. \nso keep deleting in your code like this \n```\ndel train\ndel train_images\ndel test_images\n```\n\n\nThis trick will clear all  allocated memory in GPU\n\n\"https://www.kaggle.com/titericz/baseline-transfer-learning-randomforest-gpu\"\n\n```\nfrom numba import cuda\ncuda.select_device(0)\ncuda.close()\ncuda.select_device(0)\n```\n\n\nand of course, decrease the `batch_size`",
      "votes": null
    },
    {
      "id": "1246672",
      "postDate": "03/21/2021 01:53:00",
      "content": "<p>I keep getting \"Notebook Exceeded Allowed Compute\"  as well even though I use models and data sizes that are smaller than my previously submitted notebooks. Not sure what to do. I store the image batches as tf records and delete each file after prediction. I use rle_encode_less_memory().</p>",
      "rawMarkdown": "I keep getting \"Notebook Exceeded Allowed Compute\"  as well even though I use models and data sizes that are smaller than my previously submitted notebooks. Not sure what to do. I store the image batches as tf records and delete each file after prediction. I use rle_encode_less_memory().",
      "votes": null
    },
    {
      "id": "1290552",
      "postDate": "05/02/2021 05:54:09",
      "content": "<p>Have you solved it？ I met the same trouble</p>",
      "rawMarkdown": "Have you solved it？ I met the same trouble",
      "votes": null
    },
    {
      "id": "1291228",
      "postDate": "05/02/2021 20:06:02",
      "content": "<p>Yes. you have to load the model, use it then delete it after each image segmentation. <br>\nMy code looks some thing like this now</p>\n<pre><code>model = get_model()\n    model.load_weights('../input/pretrined-mobile-attention-net/mobile_attention_net_randcrop_512.h5')\n    print('model_loaded')\n    for (x1, x2, y1, y2) in tqdm(slices, desc=f'{img_file}'):\n        if img_data.count == 3: # normal\n            img = img_data.read(\n                [1, 2, 3], \n                window=Window.from_slices((x1, x2), (y1, y2))\n            )\n            img = np.moveaxis(img, 0, -1)\n        else: # with subdatasets/layers\n            img = np.zeros((tile_resized, tile_resized, 3), dtype=np.uint8)\n            for fl in range(3):\n                img[:, :, fl] = layers[fl].read(\n                    window=Window.from_slices((x1, x2), (y1, y2))\n                )\n        img = cv2.resize(img, (tile_size, tile_size))\n        pred = np.zeros((tile_size, tile_size), dtype=np.float32)\n        for tta_mode in TTAS:\n            img_aug = flip(img, axis=tta_mode)\n            img_aug = np.expand_dims(img_aug, 0)\n            img_aug = img_aug.astype(np.float32) / 255\n            pred_aug = np.zeros((tile_size, tile_size), dtype=np.float32)\n            pred_aug += np.squeeze(model.predict(img_aug)) \n            pred += flip(pred_aug, axis=tta_mode) / len(TTAS)\n        pred = cv2.resize(pred, (tile_resized, tile_resized))\n        img_preds[x1:x2, y1:y2] = img_preds[x1:x2, y1:y2] + \\\n            (pred &gt; THRESHOLD).astype(np.uint8)\n    del model, img, pred, img_aug, pred_aug; gc.collect()\n</code></pre>",
      "rawMarkdown": "Yes. you have to load the model, use it then delete it after each image segmentation. \nMy code looks some thing like this now\n```\nmodel = get_model()\n    model.load_weights('../input/pretrined-mobile-attention-net/mobile_attention_net_randcrop_512.h5')\n    print('model_loaded')\n    for (x1, x2, y1, y2) in tqdm(slices, desc=f'{img_file}'):\n        if img_data.count == 3: # normal\n            img = img_data.read(\n                [1, 2, 3], \n                window=Window.from_slices((x1, x2), (y1, y2))\n            )\n            img = np.moveaxis(img, 0, -1)\n        else: # with subdatasets/layers\n            img = np.zeros((tile_resized, tile_resized, 3), dtype=np.uint8)\n            for fl in range(3):\n                img[:, :, fl] = layers[fl].read(\n                    window=Window.from_slices((x1, x2), (y1, y2))\n                )\n        img = cv2.resize(img, (tile_size, tile_size))\n        pred = np.zeros((tile_size, tile_size), dtype=np.float32)\n        for tta_mode in TTAS:\n            img_aug = flip(img, axis=tta_mode)\n            img_aug = np.expand_dims(img_aug, 0)\n            img_aug = img_aug.astype(np.float32) / 255\n            pred_aug = np.zeros((tile_size, tile_size), dtype=np.float32)\n            pred_aug += np.squeeze(model.predict(img_aug)) \n            pred += flip(pred_aug, axis=tta_mode) / len(TTAS)\n        pred = cv2.resize(pred, (tile_resized, tile_resized))\n        img_preds[x1:x2, y1:y2] = img_preds[x1:x2, y1:y2] + \\\n            (pred > THRESHOLD).astype(np.uint8)\n    del model, img, pred, img_aug, pred_aug; gc.collect()\n```",
      "votes": null
    },
    {
      "id": "1332576",
      "postDate": "06/02/2021 07:39:55",
      "content": "<p><a href=\"https://www.kaggle.com/nehadhimiz\" target=\"_blank\">@nehadhimiz</a> how you solved this problem??</p>",
      "rawMarkdown": "nehadhimiz how you solved this problem??",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1224688,
      "author_name": "faisalalsrheed",
      "author_url": "",
      "post_date": "03/03/2021 01:29:03",
      "content": "<p>it is a memory problem. <br>\nso keep deleting in your code like this </p>\n<pre><code>del train\ndel train_images\ndel test_images\n</code></pre>\n<p>This trick will clear all  allocated memory in GPU</p>\n<p>\"https://www.kaggle.com/titericz/baseline-transfer-learning-randomforest-gpu\"</p>\n<pre><code>from numba import cuda\ncuda.select_device(0)\ncuda.close()\ncuda.select_device(0)\n</code></pre>\n<p>and of course, decrease the <code>batch_size</code></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1246672,
      "author_name": "nehadhimiz",
      "author_url": "",
      "post_date": "03/21/2021 01:53:00",
      "content": "<p>I keep getting \"Notebook Exceeded Allowed Compute\"  as well even though I use models and data sizes that are smaller than my previously submitted notebooks. Not sure what to do. I store the image batches as tf records and delete each file after prediction. I use rle_encode_less_memory().</p>",
      "votes": null,
      "replies": [
        {
          "id": 1332576,
          "author_name": "tayyabahussain",
          "author_url": "",
          "post_date": "06/02/2021 07:39:55",
          "content": "<p><a href=\"https://www.kaggle.com/nehadhimiz\" target=\"_blank\">@nehadhimiz</a> how you solved this problem??</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1290552,
      "author_name": "puyuzhou",
      "author_url": "",
      "post_date": "05/02/2021 05:54:09",
      "content": "<p>Have you solved it？ I met the same trouble</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1291228,
      "author_name": "nehadhimiz",
      "author_url": "",
      "post_date": "05/02/2021 20:06:02",
      "content": "<p>Yes. you have to load the model, use it then delete it after each image segmentation. <br>\nMy code looks some thing like this now</p>\n<pre><code>model = get_model()\n    model.load_weights('../input/pretrined-mobile-attention-net/mobile_attention_net_randcrop_512.h5')\n    print('model_loaded')\n    for (x1, x2, y1, y2) in tqdm(slices, desc=f'{img_file}'):\n        if img_data.count == 3: # normal\n            img = img_data.read(\n                [1, 2, 3], \n                window=Window.from_slices((x1, x2), (y1, y2))\n            )\n            img = np.moveaxis(img, 0, -1)\n        else: # with subdatasets/layers\n            img = np.zeros((tile_resized, tile_resized, 3), dtype=np.uint8)\n            for fl in range(3):\n                img[:, :, fl] = layers[fl].read(\n                    window=Window.from_slices((x1, x2), (y1, y2))\n                )\n        img = cv2.resize(img, (tile_size, tile_size))\n        pred = np.zeros((tile_size, tile_size), dtype=np.float32)\n        for tta_mode in TTAS:\n            img_aug = flip(img, axis=tta_mode)\n            img_aug = np.expand_dims(img_aug, 0)\n            img_aug = img_aug.astype(np.float32) / 255\n            pred_aug = np.zeros((tile_size, tile_size), dtype=np.float32)\n            pred_aug += np.squeeze(model.predict(img_aug)) \n            pred += flip(pred_aug, axis=tta_mode) / len(TTAS)\n        pred = cv2.resize(pred, (tile_resized, tile_resized))\n        img_preds[x1:x2, y1:y2] = img_preds[x1:x2, y1:y2] + \\\n            (pred &gt; THRESHOLD).astype(np.uint8)\n    del model, img, pred, img_aug, pred_aug; gc.collect()\n</code></pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1222894": "I can run the public test successfully in my kernel，but encountered Notebook Exceeded Allowed Compute every time I submit, can somebody tell me what the problem is?",
    "1224688": "it is a memory problem. \nso keep deleting in your code like this \n```\ndel train\ndel train_images\ndel test_images\n```\n\n\nThis trick will clear all  allocated memory in GPU\n\n\"https://www.kaggle.com/titericz/baseline-transfer-learning-randomforest-gpu\"\n\n```\nfrom numba import cuda\ncuda.select_device(0)\ncuda.close()\ncuda.select_device(0)\n```\n\n\nand of course, decrease the `batch_size`",
    "1246672": "I keep getting \"Notebook Exceeded Allowed Compute\"  as well even though I use models and data sizes that are smaller than my previously submitted notebooks. Not sure what to do. I store the image batches as tf records and delete each file after prediction. I use rle_encode_less_memory().",
    "1290552": "Have you solved it？ I met the same trouble",
    "1291228": "Yes. you have to load the model, use it then delete it after each image segmentation. \nMy code looks some thing like this now\n```\nmodel = get_model()\n    model.load_weights('../input/pretrined-mobile-attention-net/mobile_attention_net_randcrop_512.h5')\n    print('model_loaded')\n    for (x1, x2, y1, y2) in tqdm(slices, desc=f'{img_file}'):\n        if img_data.count == 3: # normal\n            img = img_data.read(\n                [1, 2, 3], \n                window=Window.from_slices((x1, x2), (y1, y2))\n            )\n            img = np.moveaxis(img, 0, -1)\n        else: # with subdatasets/layers\n            img = np.zeros((tile_resized, tile_resized, 3), dtype=np.uint8)\n            for fl in range(3):\n                img[:, :, fl] = layers[fl].read(\n                    window=Window.from_slices((x1, x2), (y1, y2))\n                )\n        img = cv2.resize(img, (tile_size, tile_size))\n        pred = np.zeros((tile_size, tile_size), dtype=np.float32)\n        for tta_mode in TTAS:\n            img_aug = flip(img, axis=tta_mode)\n            img_aug = np.expand_dims(img_aug, 0)\n            img_aug = img_aug.astype(np.float32) / 255\n            pred_aug = np.zeros((tile_size, tile_size), dtype=np.float32)\n            pred_aug += np.squeeze(model.predict(img_aug)) \n            pred += flip(pred_aug, axis=tta_mode) / len(TTAS)\n        pred = cv2.resize(pred, (tile_resized, tile_resized))\n        img_preds[x1:x2, y1:y2] = img_preds[x1:x2, y1:y2] + \\\n            (pred > THRESHOLD).astype(np.uint8)\n    del model, img, pred, img_aug, pred_aug; gc.collect()\n```",
    "1332576": "nehadhimiz how you solved this problem??"
  },
  "source": "meta"
}