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;
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
add a comment |
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
add a comment |
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
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
python dataset readfile
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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