{
  "id": 232440,
  "title": "Keras fit_generator method taking too much time",
  "url": "/competitions/plant-pathology-2021-fgvc8/discussion/232440",
  "author_name": "",
  "post_date": "2021-04-13T18:08:59.799675300Z",
  "votes": null,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I am training a Image classification model, and I am using Keras' fit_generator method, but it is literally taking too much time, is there any way I can reduce this training time somehow?</p>",
  "messages": [
    {
      "id": "1272742",
      "postDate": "04/13/2021 18:08:59",
      "content": "<p>I am training a Image classification model, and I am using Keras' fit_generator method, but it is literally taking too much time, is there any way I can reduce this training time somehow?</p>",
      "rawMarkdown": "I am training a Image classification model, and I am using Keras' fit_generator method, but it is literally taking too much time, is there any way I can reduce this training time somehow?",
      "votes": null
    },
    {
      "id": "1274949",
      "postDate": "04/15/2021 18:35:02",
      "content": "<p>Hi Debjyoti Banerjee, </p>\n<p>The<a href=\"https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit_generator\" target=\"_blank\"> 'fit_generator' method is deprecated</a> and you can use the 'fit'. </p>\n<p>Maybe it can be part of the solucion to speed things up to you.<br>\nRegards</p>",
      "rawMarkdown": "Hi Debjyoti Banerjee, \n\nThe[ 'fit_generator' method is deprecated](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit_generator) and you can use the 'fit'. \n\nMaybe it can be part of the solucion to speed things up to you.\nRegards",
      "votes": null
    },
    {
      "id": "1275070",
      "postDate": "04/15/2021 22:03:02",
      "content": "<p>Thanks for suggesting, but the reason why I am using fit_generator is because, if I use fit method, then it will load all the images on RAM, and may be some memory error may come up, but if you can suggest me some other method, then it would be  really helpful </p>",
      "rawMarkdown": "Thanks for suggesting, but the reason why I am using fit_generator is because, if I use fit method, then it will load all the images on RAM, and may be some memory error may come up, but if you can suggest me some other method, then it would be  really helpful",
      "votes": null
    },
    {
      "id": "1275129",
      "postDate": "04/16/2021 01:12:32",
      "content": "<p>I am also struggling to speed things up without pre-trained network, as a knowledge approach.</p>\n<p>I tried 3 methods:</p>\n<p>1 - dataset using 'images_from_directory', but it could not find the image files. I don't know why but I think is due to filenames starting with number. (If you know how to solve it, I do appreciate)</p>\n<p>2 - dataset using map mode. Build a dataset with ( 'path-to-file', 'label'), then map 'path-to-file' to image array.</p>\n<p>3 - using generator and fit method. (not fit_generator) </p>\n<p>All of them seems to be quite similar in time, even in Kaggle's GPUs.</p>\n<p>For datasets, I found <a href=\"https://www.tensorflow.org/tutorials/images/classification\" target=\"_blank\">this tutorial </a> in Tensorflow website.  Check the 'Configure the dataset for  performance' topic. </p>\n<p>Use cache and prefetch. The first epoch will last long. From the 2nd it may be faster. For me, shuffle seems to slow down.</p>\n<p>I hope it helps</p>",
      "rawMarkdown": "I am also struggling to speed things up without pre-trained network, as a knowledge approach.\n\nI tried 3 methods:\n\n1 - dataset using 'images_from_directory', but it could not find the image files. I don't know why but I think is due to filenames starting with number. (If you know how to solve it, I do appreciate)\n\n2 - dataset using map mode. Build a dataset with ( 'path-to-file', 'label'), then map 'path-to-file' to image array.\n\n3 - using generator and fit method. (not fit_generator) \n\nAll of them seems to be quite similar in time, even in Kaggle's GPUs.\n\nFor datasets, I found [this tutorial ](https://www.tensorflow.org/tutorials/images/classification) in Tensorflow website.  Check the 'Configure the dataset for  performance' topic. \n\nUse cache and prefetch. The first epoch will last long. From the 2nd it may be faster. For me, shuffle seems to slow down.\n\nI hope it helps",
      "votes": null
    },
    {
      "id": "1275432",
      "postDate": "04/16/2021 09:49:45",
      "content": "<p>Try using pytorch, I guess there is no other option other than that, I am also going to use the same</p>",
      "rawMarkdown": "Try using pytorch, I guess there is no other option other than that, I am also going to use the same",
      "votes": null
    },
    {
      "id": "1278297",
      "postDate": "04/19/2021 18:05:00",
      "content": "<p><a href=\"https://wrosinski.github.io/deep-learning-frameworks/\" target=\"_blank\">https://wrosinski.github.io/deep-learning-frameworks/</a><br>\nHere it is shown that models based on tensorflow are much faster compared to keras and pytorch.</p>",
      "rawMarkdown": "https://wrosinski.github.io/deep-learning-frameworks/\nHere it is shown that models based on tensorflow are much faster compared to keras and pytorch.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1274949,
      "author_name": "thalesgaluchi",
      "author_url": "",
      "post_date": "04/15/2021 18:35:02",
      "content": "<p>Hi Debjyoti Banerjee, </p>\n<p>The<a href=\"https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit_generator\" target=\"_blank\"> 'fit_generator' method is deprecated</a> and you can use the 'fit'. </p>\n<p>Maybe it can be part of the solucion to speed things up to you.<br>\nRegards</p>",
      "votes": null,
      "replies": [
        {
          "id": 1275070,
          "author_name": "jl18pg052",
          "author_url": "",
          "post_date": "04/15/2021 22:03:02",
          "content": "<p>Thanks for suggesting, but the reason why I am using fit_generator is because, if I use fit method, then it will load all the images on RAM, and may be some memory error may come up, but if you can suggest me some other method, then it would be  really helpful </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1275129,
          "author_name": "thalesgaluchi",
          "author_url": "",
          "post_date": "04/16/2021 01:12:32",
          "content": "<p>I am also struggling to speed things up without pre-trained network, as a knowledge approach.</p>\n<p>I tried 3 methods:</p>\n<p>1 - dataset using 'images_from_directory', but it could not find the image files. I don't know why but I think is due to filenames starting with number. (If you know how to solve it, I do appreciate)</p>\n<p>2 - dataset using map mode. Build a dataset with ( 'path-to-file', 'label'), then map 'path-to-file' to image array.</p>\n<p>3 - using generator and fit method. (not fit_generator) </p>\n<p>All of them seems to be quite similar in time, even in Kaggle's GPUs.</p>\n<p>For datasets, I found <a href=\"https://www.tensorflow.org/tutorials/images/classification\" target=\"_blank\">this tutorial </a> in Tensorflow website.  Check the 'Configure the dataset for  performance' topic. </p>\n<p>Use cache and prefetch. The first epoch will last long. From the 2nd it may be faster. For me, shuffle seems to slow down.</p>\n<p>I hope it helps</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1275432,
          "author_name": "jl18pg052",
          "author_url": "",
          "post_date": "04/16/2021 09:49:45",
          "content": "<p>Try using pytorch, I guess there is no other option other than that, I am also going to use the same</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1278297,
      "author_name": "jl18pg052",
      "author_url": "",
      "post_date": "04/19/2021 18:05:00",
      "content": "<p><a href=\"https://wrosinski.github.io/deep-learning-frameworks/\" target=\"_blank\">https://wrosinski.github.io/deep-learning-frameworks/</a><br>\nHere it is shown that models based on tensorflow are much faster compared to keras and pytorch.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1272742": "I am training a Image classification model, and I am using Keras' fit_generator method, but it is literally taking too much time, is there any way I can reduce this training time somehow?",
    "1274949": "Hi Debjyoti Banerjee, \n\nThe[ 'fit_generator' method is deprecated](https://www.tensorflow.org/api_docs/python/tf/keras/Model#fit_generator) and you can use the 'fit'. \n\nMaybe it can be part of the solucion to speed things up to you.\nRegards",
    "1275070": "Thanks for suggesting, but the reason why I am using fit_generator is because, if I use fit method, then it will load all the images on RAM, and may be some memory error may come up, but if you can suggest me some other method, then it would be  really helpful",
    "1275129": "I am also struggling to speed things up without pre-trained network, as a knowledge approach.\n\nI tried 3 methods:\n\n1 - dataset using 'images_from_directory', but it could not find the image files. I don't know why but I think is due to filenames starting with number. (If you know how to solve it, I do appreciate)\n\n2 - dataset using map mode. Build a dataset with ( 'path-to-file', 'label'), then map 'path-to-file' to image array.\n\n3 - using generator and fit method. (not fit_generator) \n\nAll of them seems to be quite similar in time, even in Kaggle's GPUs.\n\nFor datasets, I found [this tutorial ](https://www.tensorflow.org/tutorials/images/classification) in Tensorflow website.  Check the 'Configure the dataset for  performance' topic. \n\nUse cache and prefetch. The first epoch will last long. From the 2nd it may be faster. For me, shuffle seems to slow down.\n\nI hope it helps",
    "1275432": "Try using pytorch, I guess there is no other option other than that, I am also going to use the same",
    "1278297": "https://wrosinski.github.io/deep-learning-frameworks/\nHere it is shown that models based on tensorflow are much faster compared to keras and pytorch."
  },
  "source": "meta"
}