Using os.listdir() to read images from LFW dataset can only read images from the first file folderRead only the first line of a file?Importing files from different folder“Large data” work flows using pandasReading JSON from a file?How to import all images from a user specified folder in python using pygamePython Read multiple images from multiple foldersHow to create dataset in the same format as the FSNS dataset from just a directory of imagesHow save file after processing in python?How to read the shape of all images and display them, present in a dataset folder through google colab?Fastest way to read an image from huge uncompressed tar file in __getitem__ of PyTorch custom dataset

How should the player unlock things?

How to remove the first colon ':' from a timestamp?

FPGA CPU's, how to find the max speed?

How to say no to more work as a PhD student so I can graduate

Why should I cook the flour first when making bechamel sauce?

What do these three diagonal lines that cross through three measures and both staves mean, and what are they called?

When does Fisher's "go get more data" approach make sense?

Creating a character, is Noble a class or a background?

Why isn't aluminium involved in biological processes?

What made Windows ME so crash-prone?

Is this artwork (used in a video game) real?

What are "full piece" and "half piece" in chess?

Did 007 exist before James Bond?

How Efficient Could Anaerobic Megafauna Be?

Interviewing with an unmentioned 9 months of sick leave taken during a job

Finding the package which provides a given command

How fast does a character need to move to be effectively invisible?

Is it OK to use personal email ID for faculty job applications or should we use (current) institute's ID

Sankhara meditation

Index Uniqueness Overhead

What is the goal and toolset of philosophy?

Using two linked programs, output ordinal numbers up to n

License validity of unreleased project

Why did Steve Rogers choose this character in Endgame?



Using os.listdir() to read images from LFW dataset can only read images from the first file folder


Read only the first line of a file?Importing files from different folder“Large data” work flows using pandasReading JSON from a file?How to import all images from a user specified folder in python using pygamePython Read multiple images from multiple foldersHow to create dataset in the same format as the FSNS dataset from just a directory of imagesHow save file after processing in python?How to read the shape of all images and display them, present in a dataset folder through google colab?Fastest way to read an image from huge uncompressed tar file in __getitem__ of PyTorch custom dataset






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















LFW dataset put images in different folders based on names. I want to read and move all images to one folder. I used a for loop with os.listdir() function to read the file, but it only returns an image from the first folder in LFW dataset.



'''code is showing below the line'''

import os
from os.path import join as pjoin
from skimage import io
img_dir = 'new path'
def load_data(data_dir): #dataset is the originalPath

count = 0
for guys in os.listdir(data_dir):
print(guys)
person_dir = pjoin(data_dir, guys)
for i in os.listdir(person_dir):
image_dir = pjoin(person_dir, i)
img22 = io.imread(image_dir, mode='RGB')
print(image_dir)
io.imsave(pjoin(img_dir, i), img22)
count = count+1
print(person_dir)
print(count)
return count

sourcepath = 'originalPath'
load_data(sourcepath)


The expected result is all images from all folders of LFW dataset are read to the new path (not in any folder, only images.)
The code runs with no error, but the count actually returns '1' and I can see in the new path, there's only 1 image, which was in the first folder of the LFW dataset.










share|improve this question






























    2















    LFW dataset put images in different folders based on names. I want to read and move all images to one folder. I used a for loop with os.listdir() function to read the file, but it only returns an image from the first folder in LFW dataset.



    '''code is showing below the line'''

    import os
    from os.path import join as pjoin
    from skimage import io
    img_dir = 'new path'
    def load_data(data_dir): #dataset is the originalPath

    count = 0
    for guys in os.listdir(data_dir):
    print(guys)
    person_dir = pjoin(data_dir, guys)
    for i in os.listdir(person_dir):
    image_dir = pjoin(person_dir, i)
    img22 = io.imread(image_dir, mode='RGB')
    print(image_dir)
    io.imsave(pjoin(img_dir, i), img22)
    count = count+1
    print(person_dir)
    print(count)
    return count

    sourcepath = 'originalPath'
    load_data(sourcepath)


    The expected result is all images from all folders of LFW dataset are read to the new path (not in any folder, only images.)
    The code runs with no error, but the count actually returns '1' and I can see in the new path, there's only 1 image, which was in the first folder of the LFW dataset.










    share|improve this question


























      2












      2








      2








      LFW dataset put images in different folders based on names. I want to read and move all images to one folder. I used a for loop with os.listdir() function to read the file, but it only returns an image from the first folder in LFW dataset.



      '''code is showing below the line'''

      import os
      from os.path import join as pjoin
      from skimage import io
      img_dir = 'new path'
      def load_data(data_dir): #dataset is the originalPath

      count = 0
      for guys in os.listdir(data_dir):
      print(guys)
      person_dir = pjoin(data_dir, guys)
      for i in os.listdir(person_dir):
      image_dir = pjoin(person_dir, i)
      img22 = io.imread(image_dir, mode='RGB')
      print(image_dir)
      io.imsave(pjoin(img_dir, i), img22)
      count = count+1
      print(person_dir)
      print(count)
      return count

      sourcepath = 'originalPath'
      load_data(sourcepath)


      The expected result is all images from all folders of LFW dataset are read to the new path (not in any folder, only images.)
      The code runs with no error, but the count actually returns '1' and I can see in the new path, there's only 1 image, which was in the first folder of the LFW dataset.










      share|improve this question
















      LFW dataset put images in different folders based on names. I want to read and move all images to one folder. I used a for loop with os.listdir() function to read the file, but it only returns an image from the first folder in LFW dataset.



      '''code is showing below the line'''

      import os
      from os.path import join as pjoin
      from skimage import io
      img_dir = 'new path'
      def load_data(data_dir): #dataset is the originalPath

      count = 0
      for guys in os.listdir(data_dir):
      print(guys)
      person_dir = pjoin(data_dir, guys)
      for i in os.listdir(person_dir):
      image_dir = pjoin(person_dir, i)
      img22 = io.imread(image_dir, mode='RGB')
      print(image_dir)
      io.imsave(pjoin(img_dir, i), img22)
      count = count+1
      print(person_dir)
      print(count)
      return count

      sourcepath = 'originalPath'
      load_data(sourcepath)


      The expected result is all images from all folders of LFW dataset are read to the new path (not in any folder, only images.)
      The code runs with no error, but the count actually returns '1' and I can see in the new path, there's only 1 image, which was in the first folder of the LFW dataset.







      python dataset readfile






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 8:16









      taras

      3,6606 gold badges26 silver badges35 bronze badges




      3,6606 gold badges26 silver badges35 bronze badges










      asked Mar 26 at 8:16









      Karis.LKaris.L

      133 bronze badges




      133 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          One obvious problem is indentation of your return statement:



          '''code is showing below the line'''

          import os
          from os.path import join as pjoin
          from skimage import io
          img_dir = 'new path'
          def load_data(data_dir): #dataset is the originalPath

          count = 0
          for guys in os.listdir(data_dir):
          print(guys)
          person_dir = pjoin(data_dir, guys)
          for i in os.listdir(person_dir):
          image_dir = pjoin(person_dir, i)
          img22 = io.imread(image_dir, mode='RGB')
          print(image_dir)
          io.imsave(pjoin(img_dir, i), img22)
          count = count+1
          print(person_dir)
          print(count)
          return count

          sourcepath = 'originalPath'
          load_data(sourcepath)


          Can you check and confirm if the first folder (guys) it is working for has more than one images.






          share|improve this answer























          • Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

            – Karis.L
            Mar 26 at 9:01










          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%2f55352532%2fusing-os-listdir-to-read-images-from-lfw-dataset-can-only-read-images-from-the%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









          0














          One obvious problem is indentation of your return statement:



          '''code is showing below the line'''

          import os
          from os.path import join as pjoin
          from skimage import io
          img_dir = 'new path'
          def load_data(data_dir): #dataset is the originalPath

          count = 0
          for guys in os.listdir(data_dir):
          print(guys)
          person_dir = pjoin(data_dir, guys)
          for i in os.listdir(person_dir):
          image_dir = pjoin(person_dir, i)
          img22 = io.imread(image_dir, mode='RGB')
          print(image_dir)
          io.imsave(pjoin(img_dir, i), img22)
          count = count+1
          print(person_dir)
          print(count)
          return count

          sourcepath = 'originalPath'
          load_data(sourcepath)


          Can you check and confirm if the first folder (guys) it is working for has more than one images.






          share|improve this answer























          • Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

            – Karis.L
            Mar 26 at 9:01















          0














          One obvious problem is indentation of your return statement:



          '''code is showing below the line'''

          import os
          from os.path import join as pjoin
          from skimage import io
          img_dir = 'new path'
          def load_data(data_dir): #dataset is the originalPath

          count = 0
          for guys in os.listdir(data_dir):
          print(guys)
          person_dir = pjoin(data_dir, guys)
          for i in os.listdir(person_dir):
          image_dir = pjoin(person_dir, i)
          img22 = io.imread(image_dir, mode='RGB')
          print(image_dir)
          io.imsave(pjoin(img_dir, i), img22)
          count = count+1
          print(person_dir)
          print(count)
          return count

          sourcepath = 'originalPath'
          load_data(sourcepath)


          Can you check and confirm if the first folder (guys) it is working for has more than one images.






          share|improve this answer























          • Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

            – Karis.L
            Mar 26 at 9:01













          0












          0








          0







          One obvious problem is indentation of your return statement:



          '''code is showing below the line'''

          import os
          from os.path import join as pjoin
          from skimage import io
          img_dir = 'new path'
          def load_data(data_dir): #dataset is the originalPath

          count = 0
          for guys in os.listdir(data_dir):
          print(guys)
          person_dir = pjoin(data_dir, guys)
          for i in os.listdir(person_dir):
          image_dir = pjoin(person_dir, i)
          img22 = io.imread(image_dir, mode='RGB')
          print(image_dir)
          io.imsave(pjoin(img_dir, i), img22)
          count = count+1
          print(person_dir)
          print(count)
          return count

          sourcepath = 'originalPath'
          load_data(sourcepath)


          Can you check and confirm if the first folder (guys) it is working for has more than one images.






          share|improve this answer













          One obvious problem is indentation of your return statement:



          '''code is showing below the line'''

          import os
          from os.path import join as pjoin
          from skimage import io
          img_dir = 'new path'
          def load_data(data_dir): #dataset is the originalPath

          count = 0
          for guys in os.listdir(data_dir):
          print(guys)
          person_dir = pjoin(data_dir, guys)
          for i in os.listdir(person_dir):
          image_dir = pjoin(person_dir, i)
          img22 = io.imread(image_dir, mode='RGB')
          print(image_dir)
          io.imsave(pjoin(img_dir, i), img22)
          count = count+1
          print(person_dir)
          print(count)
          return count

          sourcepath = 'originalPath'
          load_data(sourcepath)


          Can you check and confirm if the first folder (guys) it is working for has more than one images.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 8:25









          DineshDinesh

          1,1021 gold badge12 silver badges15 bronze badges




          1,1021 gold badge12 silver badges15 bronze badges












          • Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

            – Karis.L
            Mar 26 at 9:01

















          • Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

            – Karis.L
            Mar 26 at 9:01
















          Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

          – Karis.L
          Mar 26 at 9:01





          Thanks a lot, Dinesh. I didn't realize there is a "return count", I was supposed to print(count) and return. After removing the return count the code works well.

          – Karis.L
          Mar 26 at 9:01






          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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%2f55352532%2fusing-os-listdir-to-read-images-from-lfw-dataset-can-only-read-images-from-the%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현