{
  "id": 139039,
  "title": "Keras preprocess_input()",
  "url": "/competitions/deepfake-detection-challenge/discussion/139039",
  "author_name": "",
  "post_date": "2020-03-27T06:34:31.618232800Z",
  "votes": 1,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Hello,</p>\n\n<p>Anybody used preproces_input() for a pre-trained model on Keras? When I run my code without calling this preprocess function, it runs smoothly and commits. But as I use this, I see my RAM usage shoots up and is causing an error on committing (more memory than allocated used up). Pls help!</p>",
  "messages": [
    {
      "id": "787865",
      "postDate": "03/27/2020 06:34:31",
      "content": "<p>Hello,</p>\n\n<p>Anybody used preproces_input() for a pre-trained model on Keras? When I run my code without calling this preprocess function, it runs smoothly and commits. But as I use this, I see my RAM usage shoots up and is causing an error on committing (more memory than allocated used up). Pls help!</p>",
      "rawMarkdown": "Hello,\n\nAnybody used preproces_input() for a pre-trained model on Keras? When I run my code without calling this preprocess function, it runs smoothly and commits. But as I use this, I see my RAM usage shoots up and is causing an error on committing (more memory than allocated used up). Pls help!",
      "votes": null
    },
    {
      "id": "788522",
      "postDate": "03/27/2020 18:36:34",
      "content": "<p>I've  already got this message \"more memory than allocated used up\"  even not using Keras. Then I stopped the Notebook  and restarted it again. Sometimes even the Notebooks stop when I'm  writing for a longer time.</p>",
      "rawMarkdown": "I've  already got this message \"more memory than allocated used up\"  even not using Keras. Then I stopped the Notebook  and restarted it again. Sometimes even the Notebooks stop when I'm  writing for a longer time.",
      "votes": null
    },
    {
      "id": "788598",
      "postDate": "03/27/2020 19:42:09",
      "content": "<p>How many images are you loading at the same time? Note that a single image of size HxW takes up HxWx3x4 bytes in memory. If the image is 1920x1080 pixels, that is 24 MB. If you load 10 of these images, it is 240 MB. If you load 100, it is 2.4 GB. And so on...</p>\n\n<p>Doing something like preprocessing will allocate temporary space for the new image, and possible for temporary in-between images as well. It can fill up memory quickly!</p>",
      "rawMarkdown": "How many images are you loading at the same time? Note that a single image of size HxW takes up HxWx3x4 bytes in memory. If the image is 1920x1080 pixels, that is 24 MB. If you load 10 of these images, it is 240 MB. If you load 100, it is 2.4 GB. And so on...\n\nDoing something like preprocessing will allocate temporary space for the new image, and possible for temporary in-between images as well. It can fill up memory quickly!",
      "votes": null
    },
    {
      "id": "788818",
      "postDate": "03/28/2020 03:43:51",
      "content": "<p>Actually, I am preprocessing one video at a time, which is 20 frames in my case, and the output is a numpy array of dimension (1, 20, 299, 299, 3) where 299 is H and W. As I oversampled, so 540 of such videos are preprocessed one at a time, but the final result that is (540, 20, 299, 299, 3) is stored in RAM. This was running smoothly when I did not normalize, which I should do as I am using a pre-trained model for feature extraction from faces captured. But now when I use preprocess_input() of Keras, or even manually call np.divide(), np.subtract(),  np.multiply() for normalization, memory allocation is shooting up. Pls help! Is there some other way of normalizing?</p>",
      "rawMarkdown": "Actually, I am preprocessing one video at a time, which is 20 frames in my case, and the output is a numpy array of dimension (1, 20, 299, 299, 3) where 299 is H and W. As I oversampled, so 540 of such videos are preprocessed one at a time, but the final result that is (540, 20, 299, 299, 3) is stored in RAM. This was running smoothly when I did not normalize, which I should do as I am using a pre-trained model for feature extraction from faces captured. But now when I use preprocess_input() of Keras, or even manually call np.divide(), np.subtract(),  np.multiply() for normalization, memory allocation is shooting up. Pls help! Is there some other way of normalizing?",
      "votes": null
    },
    {
      "id": "789085",
      "postDate": "03/28/2020 11:21:46",
      "content": "<p><code>540 * 20 * 299 * 299 * 3 * 4 = 10.8 GB</code> (if stored as 32-bit floats). When you try to normalize this, it will probably try to allocate another 10.8 GB tensor. That won't fit in RAM.</p>\n\n<p>In other words, you cannot process these 540 videos at the same time.</p>",
      "rawMarkdown": "`540 * 20 * 299 * 299 * 3 * 4 = 10.8 GB` (if stored as 32-bit floats). When you try to normalize this, it will probably try to allocate another 10.8 GB tensor. That won't fit in RAM.\n\nIn other words, you cannot process these 540 videos at the same time.",
      "votes": null
    },
    {
      "id": "789088",
      "postDate": "03/28/2020 11:25:33",
      "content": "<p>Got your point. Thank you so much!</p>",
      "rawMarkdown": "Got your point. Thank you so much!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 788522,
      "author_name": "mpwolke",
      "author_url": "",
      "post_date": "03/27/2020 18:36:34",
      "content": "<p>I've  already got this message \"more memory than allocated used up\"  even not using Keras. Then I stopped the Notebook  and restarted it again. Sometimes even the Notebooks stop when I'm  writing for a longer time.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 788598,
      "author_name": "humananalog",
      "author_url": "",
      "post_date": "03/27/2020 19:42:09",
      "content": "<p>How many images are you loading at the same time? Note that a single image of size HxW takes up HxWx3x4 bytes in memory. If the image is 1920x1080 pixels, that is 24 MB. If you load 10 of these images, it is 240 MB. If you load 100, it is 2.4 GB. And so on...</p>\n\n<p>Doing something like preprocessing will allocate temporary space for the new image, and possible for temporary in-between images as well. It can fill up memory quickly!</p>",
      "votes": null,
      "replies": [
        {
          "id": 788818,
          "author_name": "saanikagupta",
          "author_url": "",
          "post_date": "03/28/2020 03:43:51",
          "content": "<p>Actually, I am preprocessing one video at a time, which is 20 frames in my case, and the output is a numpy array of dimension (1, 20, 299, 299, 3) where 299 is H and W. As I oversampled, so 540 of such videos are preprocessed one at a time, but the final result that is (540, 20, 299, 299, 3) is stored in RAM. This was running smoothly when I did not normalize, which I should do as I am using a pre-trained model for feature extraction from faces captured. But now when I use preprocess_input() of Keras, or even manually call np.divide(), np.subtract(),  np.multiply() for normalization, memory allocation is shooting up. Pls help! Is there some other way of normalizing?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 789085,
          "author_name": "humananalog",
          "author_url": "",
          "post_date": "03/28/2020 11:21:46",
          "content": "<p><code>540 * 20 * 299 * 299 * 3 * 4 = 10.8 GB</code> (if stored as 32-bit floats). When you try to normalize this, it will probably try to allocate another 10.8 GB tensor. That won't fit in RAM.</p>\n\n<p>In other words, you cannot process these 540 videos at the same time.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 789088,
          "author_name": "saanikagupta",
          "author_url": "",
          "post_date": "03/28/2020 11:25:33",
          "content": "<p>Got your point. Thank you so much!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "787865": "Hello,\n\nAnybody used preproces_input() for a pre-trained model on Keras? When I run my code without calling this preprocess function, it runs smoothly and commits. But as I use this, I see my RAM usage shoots up and is causing an error on committing (more memory than allocated used up). Pls help!",
    "788522": "I've  already got this message \"more memory than allocated used up\"  even not using Keras. Then I stopped the Notebook  and restarted it again. Sometimes even the Notebooks stop when I'm  writing for a longer time.",
    "788598": "How many images are you loading at the same time? Note that a single image of size HxW takes up HxWx3x4 bytes in memory. If the image is 1920x1080 pixels, that is 24 MB. If you load 10 of these images, it is 240 MB. If you load 100, it is 2.4 GB. And so on...\n\nDoing something like preprocessing will allocate temporary space for the new image, and possible for temporary in-between images as well. It can fill up memory quickly!",
    "788818": "Actually, I am preprocessing one video at a time, which is 20 frames in my case, and the output is a numpy array of dimension (1, 20, 299, 299, 3) where 299 is H and W. As I oversampled, so 540 of such videos are preprocessed one at a time, but the final result that is (540, 20, 299, 299, 3) is stored in RAM. This was running smoothly when I did not normalize, which I should do as I am using a pre-trained model for feature extraction from faces captured. But now when I use preprocess_input() of Keras, or even manually call np.divide(), np.subtract(),  np.multiply() for normalization, memory allocation is shooting up. Pls help! Is there some other way of normalizing?",
    "789085": "`540 * 20 * 299 * 299 * 3 * 4 = 10.8 GB` (if stored as 32-bit floats). When you try to normalize this, it will probably try to allocate another 10.8 GB tensor. That won't fit in RAM.\n\nIn other words, you cannot process these 540 videos at the same time.",
    "789088": "Got your point. Thank you so much!"
  },
  "source": "meta"
}