Load data on demand using flow_from_directory for AutoEncoderResizing images in Keras ImageDataGenerator flow methodsHow to manually specify class labels in keras flow_from_directory?Keras: model with one input and two outputs, trained jointly on different data (semi-supervised learning)keras ImageDataGenerator flow_from_directory generated dataKeras - Variational Autoencoder NaN lossKeras ImageDataGenerator and flow_from_directory class_mode='input'Keras dimension mismatch in last layer of autoencoderValue error with dimensions in designing a simple autoencoderHow to load images for classification problem using KerasNot able to load a custom dataset

How can a function with a hole (removable discontinuity) equal a function with no hole?

How do scammers retract money, while you can’t?

Why escape if the_content isnt?

Do all network devices need to make routing decisions, regardless of communication across networks or within a network?

Unreliable Magic - Is it worth it?

How to draw lines on a tikz-cd diagram

How can we prove that any integral in the set of non-elementary integrals cannot be expressed in the form of elementary functions?

Balance Issues for a Custom Sorcerer Variant

Type int? vs type int

How to be diplomatic in refusing to write code that breaches the privacy of our users

Customer Requests (Sometimes) Drive Me Bonkers!

Is there a good way to store credentials outside of a password manager?

How can I kill an app using Terminal?

Class Action - which options I have?

Increase performance creating Mandelbrot set in python

Detecting if an element is found inside a container

Is expanding the research of a group into machine learning as a PhD student risky?

How to run a prison with the smallest amount of guards?

Was Spock the First Vulcan in Starfleet?

Proof of work - lottery approach

What is the best translation for "slot" in the context of multiplayer video games?

What can we do to stop prior company from asking us questions?

You cannot touch me, but I can touch you, who am I?

How does the UK government determine the size of a mandate?



Load data on demand using flow_from_directory for AutoEncoder


Resizing images in Keras ImageDataGenerator flow methodsHow to manually specify class labels in keras flow_from_directory?Keras: model with one input and two outputs, trained jointly on different data (semi-supervised learning)keras ImageDataGenerator flow_from_directory generated dataKeras - Variational Autoencoder NaN lossKeras ImageDataGenerator and flow_from_directory class_mode='input'Keras dimension mismatch in last layer of autoencoderValue error with dimensions in designing a simple autoencoderHow to load images for classification problem using KerasNot able to load a custom dataset













1















I am trying to train an AutoEncoder on some image data. The dataset is so huge so that it won't fit in memory. So obviously I want to load the data from the directory on demand with the help of flow_from_directory in Keras.





My dataset is in the following structure



./Dataset/
./Train/
../1.jpg
../2.jpg


and so on.



I tried to use flow_from_directory like this



train_generator = datagen.flow_from_directory(
TRAIN_FOLDER,
target_size = (256, 256),
color_mode = 'rgb',
batch_size = batch_size,
class_mode = 'input')


This gives me an output Found 0 images belonging to 0 classes. I will get a ZeroDivisionError if I try to fit the model with this generator.



I have used the flow_from_directory, flow and flow_from_dataframe in various occasions but in those cases, I was going for a classification problem and had n folders in the directory for n classes.



How can I load images from the directory on demand for training auto encoder.? From the Keras docs over here I saw



class_mode : "input" will be images identical to input images (mainly used to work with autoencoders)



But this is not fixing the problem either.



One workaround I found was making another folder inside the train and moving all the files into that. Is there any direct method other than this.?










share|improve this question




























    1















    I am trying to train an AutoEncoder on some image data. The dataset is so huge so that it won't fit in memory. So obviously I want to load the data from the directory on demand with the help of flow_from_directory in Keras.





    My dataset is in the following structure



    ./Dataset/
    ./Train/
    ../1.jpg
    ../2.jpg


    and so on.



    I tried to use flow_from_directory like this



    train_generator = datagen.flow_from_directory(
    TRAIN_FOLDER,
    target_size = (256, 256),
    color_mode = 'rgb',
    batch_size = batch_size,
    class_mode = 'input')


    This gives me an output Found 0 images belonging to 0 classes. I will get a ZeroDivisionError if I try to fit the model with this generator.



    I have used the flow_from_directory, flow and flow_from_dataframe in various occasions but in those cases, I was going for a classification problem and had n folders in the directory for n classes.



    How can I load images from the directory on demand for training auto encoder.? From the Keras docs over here I saw



    class_mode : "input" will be images identical to input images (mainly used to work with autoencoders)



    But this is not fixing the problem either.



    One workaround I found was making another folder inside the train and moving all the files into that. Is there any direct method other than this.?










    share|improve this question


























      1












      1








      1








      I am trying to train an AutoEncoder on some image data. The dataset is so huge so that it won't fit in memory. So obviously I want to load the data from the directory on demand with the help of flow_from_directory in Keras.





      My dataset is in the following structure



      ./Dataset/
      ./Train/
      ../1.jpg
      ../2.jpg


      and so on.



      I tried to use flow_from_directory like this



      train_generator = datagen.flow_from_directory(
      TRAIN_FOLDER,
      target_size = (256, 256),
      color_mode = 'rgb',
      batch_size = batch_size,
      class_mode = 'input')


      This gives me an output Found 0 images belonging to 0 classes. I will get a ZeroDivisionError if I try to fit the model with this generator.



      I have used the flow_from_directory, flow and flow_from_dataframe in various occasions but in those cases, I was going for a classification problem and had n folders in the directory for n classes.



      How can I load images from the directory on demand for training auto encoder.? From the Keras docs over here I saw



      class_mode : "input" will be images identical to input images (mainly used to work with autoencoders)



      But this is not fixing the problem either.



      One workaround I found was making another folder inside the train and moving all the files into that. Is there any direct method other than this.?










      share|improve this question
















      I am trying to train an AutoEncoder on some image data. The dataset is so huge so that it won't fit in memory. So obviously I want to load the data from the directory on demand with the help of flow_from_directory in Keras.





      My dataset is in the following structure



      ./Dataset/
      ./Train/
      ../1.jpg
      ../2.jpg


      and so on.



      I tried to use flow_from_directory like this



      train_generator = datagen.flow_from_directory(
      TRAIN_FOLDER,
      target_size = (256, 256),
      color_mode = 'rgb',
      batch_size = batch_size,
      class_mode = 'input')


      This gives me an output Found 0 images belonging to 0 classes. I will get a ZeroDivisionError if I try to fit the model with this generator.



      I have used the flow_from_directory, flow and flow_from_dataframe in various occasions but in those cases, I was going for a classification problem and had n folders in the directory for n classes.



      How can I load images from the directory on demand for training auto encoder.? From the Keras docs over here I saw



      class_mode : "input" will be images identical to input images (mainly used to work with autoencoders)



      But this is not fixing the problem either.



      One workaround I found was making another folder inside the train and moving all the files into that. Is there any direct method other than this.?







      keras deep-learning






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 13:45









      Ioannis Nasios

      3,75831036




      3,75831036










      asked Mar 8 at 11:03









      Sreeram TPSreeram TP

      3,10431440




      3,10431440






















          1 Answer
          1






          active

          oldest

          votes


















          2














          The Keras docs are indeed not very precise here and the way it actually works is not intuitive (at least to me) ...



          Here, even though you are using class_mode='input' which means that there are no classes (or each picture is its own class, however you like to phrase it), your images still have to be inside of subfolders.



          So, inside of your Train folder just create another subfolder and move all images inside. Then the output will be Found xxx images belonging to 1 classes.



          You can even have multiple subfolders, the generated X and Y data will be the same, just the console output will be different (and misleading): Found xxx images belonging to yy classes.
          This may be useful if there actually are classes and you have another model using them (using class_mode='categorical' or class_mode='binary'). Then this model can load its data from the same folder.






          share|improve this answer























          • I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

            – Sreeram TP
            Mar 8 at 12:17






          • 1





            @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

            – sebrockm
            Mar 8 at 12:24






          • 1





            Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

            – Sreeram TP
            Mar 8 at 12:28










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55061877%2fload-data-on-demand-using-flow-from-directory-for-autoencoder%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          The Keras docs are indeed not very precise here and the way it actually works is not intuitive (at least to me) ...



          Here, even though you are using class_mode='input' which means that there are no classes (or each picture is its own class, however you like to phrase it), your images still have to be inside of subfolders.



          So, inside of your Train folder just create another subfolder and move all images inside. Then the output will be Found xxx images belonging to 1 classes.



          You can even have multiple subfolders, the generated X and Y data will be the same, just the console output will be different (and misleading): Found xxx images belonging to yy classes.
          This may be useful if there actually are classes and you have another model using them (using class_mode='categorical' or class_mode='binary'). Then this model can load its data from the same folder.






          share|improve this answer























          • I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

            – Sreeram TP
            Mar 8 at 12:17






          • 1





            @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

            – sebrockm
            Mar 8 at 12:24






          • 1





            Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

            – Sreeram TP
            Mar 8 at 12:28















          2














          The Keras docs are indeed not very precise here and the way it actually works is not intuitive (at least to me) ...



          Here, even though you are using class_mode='input' which means that there are no classes (or each picture is its own class, however you like to phrase it), your images still have to be inside of subfolders.



          So, inside of your Train folder just create another subfolder and move all images inside. Then the output will be Found xxx images belonging to 1 classes.



          You can even have multiple subfolders, the generated X and Y data will be the same, just the console output will be different (and misleading): Found xxx images belonging to yy classes.
          This may be useful if there actually are classes and you have another model using them (using class_mode='categorical' or class_mode='binary'). Then this model can load its data from the same folder.






          share|improve this answer























          • I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

            – Sreeram TP
            Mar 8 at 12:17






          • 1





            @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

            – sebrockm
            Mar 8 at 12:24






          • 1





            Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

            – Sreeram TP
            Mar 8 at 12:28













          2












          2








          2







          The Keras docs are indeed not very precise here and the way it actually works is not intuitive (at least to me) ...



          Here, even though you are using class_mode='input' which means that there are no classes (or each picture is its own class, however you like to phrase it), your images still have to be inside of subfolders.



          So, inside of your Train folder just create another subfolder and move all images inside. Then the output will be Found xxx images belonging to 1 classes.



          You can even have multiple subfolders, the generated X and Y data will be the same, just the console output will be different (and misleading): Found xxx images belonging to yy classes.
          This may be useful if there actually are classes and you have another model using them (using class_mode='categorical' or class_mode='binary'). Then this model can load its data from the same folder.






          share|improve this answer













          The Keras docs are indeed not very precise here and the way it actually works is not intuitive (at least to me) ...



          Here, even though you are using class_mode='input' which means that there are no classes (or each picture is its own class, however you like to phrase it), your images still have to be inside of subfolders.



          So, inside of your Train folder just create another subfolder and move all images inside. Then the output will be Found xxx images belonging to 1 classes.



          You can even have multiple subfolders, the generated X and Y data will be the same, just the console output will be different (and misleading): Found xxx images belonging to yy classes.
          This may be useful if there actually are classes and you have another model using them (using class_mode='categorical' or class_mode='binary'). Then this model can load its data from the same folder.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 12:10









          sebrockmsebrockm

          1,735320




          1,735320












          • I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

            – Sreeram TP
            Mar 8 at 12:17






          • 1





            @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

            – sebrockm
            Mar 8 at 12:24






          • 1





            Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

            – Sreeram TP
            Mar 8 at 12:28

















          • I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

            – Sreeram TP
            Mar 8 at 12:17






          • 1





            @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

            – sebrockm
            Mar 8 at 12:24






          • 1





            Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

            – Sreeram TP
            Mar 8 at 12:28
















          I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

          – Sreeram TP
          Mar 8 at 12:17





          I did the same. Made folder called TRAIN inside Train ie Train//TRAIN and moved my image files in Train// to Train//TRAIN. Then it seems to work. I was thinking there is some other way to tell flow_from_directory there is no need to look for sub folders

          – Sreeram TP
          Mar 8 at 12:17




          1




          1





          @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

          – sebrockm
          Mar 8 at 12:24





          @SreeramTP Oh damn, I completely missed your last paragraph. Sorry. So, no, I was facing this quite often now and I'm not aware of any "direct" way of doing it.

          – sebrockm
          Mar 8 at 12:24




          1




          1





          Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

          – Sreeram TP
          Mar 8 at 12:28





          Your answer will be helpful for others who face this issue and are looking for a quick solution / workaround

          – Sreeram TP
          Mar 8 at 12:28



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55061877%2fload-data-on-demand-using-flow-from-directory-for-autoencoder%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page

          Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices