Keras flow_from_directory() read only from selected sub-directoriesHow to manually specify class labels in keras flow_from_directory?Keras ImageDataGenerator method flow_from_directoryKeras flow_from_directory class indexkeras ImageDataGenerator flow_from_directory generated dataSplit data directory into training and test directory with sub directory structure preservedDoes Keras flow_from_directory iterate through every sample in a directory?How to access images directly from Google Cloud Storage (GCS) when using Keras?Low validation accuracy with good training accuracy - keras imagedatagenerator flow_from_directory categorical classificationHow to load images for classification problem using KerasFolder structure Keras ImageDataGenerator

What STL algorithm can determine if exactly one item in a container satisfies a predicate?

Proving that a Russian cryptographic standard is too structured

60s or 70s novel about Empire of Man making 1st contact with 1st discovered alien race

Why we don’t make use of the t-distribution for constructing a confidence interval for a proportion?

How can I remove material from this wood beam?

Smart-expansion of a range to a list of numbers

Do you have to have figures when playing D&D?

Was Self-modifying-code possible just using BASIC?

UTC timestamp format for launch vehicles

Can we completely replace inheritance using strategy pattern and dependency injection?

Is Lambda Calculus purely syntactic?

Who voices the small round football sized demon In Good Omens

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?

2019 gold coins to share

How can I make 12 tone and atonal melodies sound interesting?

Can the removal of a duty-free sales trolley result in a measurable reduction in emissions?

Does the Nuka-Cola bottler actually generate nuka cola?

What would be the way to say "just saying" in German? (Not the literal translation)

Java Servlet & JSP simple login

How do we say "within a kilometer radius spherically"?

Increase speed altering column on large table to NON NULL

Are polynomials with the same roots identical?

Analogy between an unknown in an argument, and a contradiction in the principle of explosion



Keras flow_from_directory() read only from selected sub-directories


How to manually specify class labels in keras flow_from_directory?Keras ImageDataGenerator method flow_from_directoryKeras flow_from_directory class indexkeras ImageDataGenerator flow_from_directory generated dataSplit data directory into training and test directory with sub directory structure preservedDoes Keras flow_from_directory iterate through every sample in a directory?How to access images directly from Google Cloud Storage (GCS) when using Keras?Low validation accuracy with good training accuracy - keras imagedatagenerator flow_from_directory categorical classificationHow to load images for classification problem using KerasFolder structure Keras ImageDataGenerator






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have a directory structure as follows.



train
|- dog --> contains image files of dogs
|- cat --> contains image files of cats
|- elephant --> contains image files of elephants


I want to train a CNN to identify animals, but only for cats and dogs and not elephants.



I want to use keras ImageDataGenerator class to augment data and flow_from_directory() method to read the image files.



train_datagen = ImageDataGenerator(rescale=1./255)
train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True)


The above code will read data from all sub-directories of 'train', which I don't want. One option is to create a new directory and copy of 'dog' and 'cat' sub-directories along with the files inside it. But is there a way to control it from flow_from_directory() method itself?










share|improve this question




























    1















    I have a directory structure as follows.



    train
    |- dog --> contains image files of dogs
    |- cat --> contains image files of cats
    |- elephant --> contains image files of elephants


    I want to train a CNN to identify animals, but only for cats and dogs and not elephants.



    I want to use keras ImageDataGenerator class to augment data and flow_from_directory() method to read the image files.



    train_datagen = ImageDataGenerator(rescale=1./255)
    train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True)


    The above code will read data from all sub-directories of 'train', which I don't want. One option is to create a new directory and copy of 'dog' and 'cat' sub-directories along with the files inside it. But is there a way to control it from flow_from_directory() method itself?










    share|improve this question
























      1












      1








      1


      0






      I have a directory structure as follows.



      train
      |- dog --> contains image files of dogs
      |- cat --> contains image files of cats
      |- elephant --> contains image files of elephants


      I want to train a CNN to identify animals, but only for cats and dogs and not elephants.



      I want to use keras ImageDataGenerator class to augment data and flow_from_directory() method to read the image files.



      train_datagen = ImageDataGenerator(rescale=1./255)
      train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True)


      The above code will read data from all sub-directories of 'train', which I don't want. One option is to create a new directory and copy of 'dog' and 'cat' sub-directories along with the files inside it. But is there a way to control it from flow_from_directory() method itself?










      share|improve this question














      I have a directory structure as follows.



      train
      |- dog --> contains image files of dogs
      |- cat --> contains image files of cats
      |- elephant --> contains image files of elephants


      I want to train a CNN to identify animals, but only for cats and dogs and not elephants.



      I want to use keras ImageDataGenerator class to augment data and flow_from_directory() method to read the image files.



      train_datagen = ImageDataGenerator(rescale=1./255)
      train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True)


      The above code will read data from all sub-directories of 'train', which I don't want. One option is to create a new directory and copy of 'dog' and 'cat' sub-directories along with the files inside it. But is there a way to control it from flow_from_directory() method itself?







      tensorflow keras deep-learning conv-neural-network






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 20:40









      Supratim HaldarSupratim Haldar

      1,255518




      1,255518






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Assuming that I understood your question in the right way, this should help you:



          train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True, classes=["dog", "cat"])


          This will read only the images from the directories dog and cat, leave out the elephant directory and provide distinct categorical labels for them.






          share|improve this answer























          • Perfect. Thanks for your help!

            – Supratim Haldar
            Mar 25 at 5:29











          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%2f55328355%2fkeras-flow-from-directory-read-only-from-selected-sub-directories%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














          Assuming that I understood your question in the right way, this should help you:



          train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True, classes=["dog", "cat"])


          This will read only the images from the directories dog and cat, leave out the elephant directory and provide distinct categorical labels for them.






          share|improve this answer























          • Perfect. Thanks for your help!

            – Supratim Haldar
            Mar 25 at 5:29















          2














          Assuming that I understood your question in the right way, this should help you:



          train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True, classes=["dog", "cat"])


          This will read only the images from the directories dog and cat, leave out the elephant directory and provide distinct categorical labels for them.






          share|improve this answer























          • Perfect. Thanks for your help!

            – Supratim Haldar
            Mar 25 at 5:29













          2












          2








          2







          Assuming that I understood your question in the right way, this should help you:



          train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True, classes=["dog", "cat"])


          This will read only the images from the directories dog and cat, leave out the elephant directory and provide distinct categorical labels for them.






          share|improve this answer













          Assuming that I understood your question in the right way, this should help you:



          train_generator = train_datagen.flow_from_directory(directory='train', class_mode='categorical', target_size=(64,64), batch_size=16, shuffle=True, classes=["dog", "cat"])


          This will read only the images from the directories dog and cat, leave out the elephant directory and provide distinct categorical labels for them.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 21:09









          gorjangorjan

          1,652617




          1,652617












          • Perfect. Thanks for your help!

            – Supratim Haldar
            Mar 25 at 5:29

















          • Perfect. Thanks for your help!

            – Supratim Haldar
            Mar 25 at 5:29
















          Perfect. Thanks for your help!

          – Supratim Haldar
          Mar 25 at 5:29





          Perfect. Thanks for your help!

          – Supratim Haldar
          Mar 25 at 5:29



















          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%2f55328355%2fkeras-flow-from-directory-read-only-from-selected-sub-directories%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript