Reputation: 1121
Read multiple images and labels in python
This is what I want to do. However, I want to read it in batches. Is it possible to do this?
I am not planning to use default function of Keras and Tensorflow.
path = 'path to dir'
img_dict = dict()
a=[]
batch_tuple=()
def batching(batch=5):
for root, dirs, files in os.walk(path):
my_key = os.path.basename(root)
dir_images = []
dir_labels=[]
for file_ in files:
dir_images.append(full_file_path)
for ndx in range(0, len(dir_images), batch):
batch_img #list2
batch_lab #list1
return (batch_img,batch_lab)
while batch:
if 100<batch:
t=next()
print(t)
batch-=batch
# print(len(a))
I get expected result when I do following code -:
But I actually want to do using the function. like if I pass the batch size, it will return my expected output!
in every iteration, I want to get a tuple of two lists that I can print in the second code.
Upvotes: 2
Views: 843
Reputation: 934
in this line print((batch_img,batch_lab))
create a list and do as following-:
empy_list=[]
empy_list.append((batch_img,batch_lab))
no need to go with while loop i think!
i think this will give what you are expecting!
Upvotes: 1