Created
June 29, 2021 01:38
-
-
Save RishiRajak/06a1606a6ea1a698eb7d1cc3f930ad68 to your computer and use it in GitHub Desktop.
dataframe of image paths and labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getdata(folder_path,num_subfolders): | |
flowers = pd.DataFrame(columns=['image_abs_path','image_labels']) | |
for label in range(1,num_subfolders+1): | |
#print("processing for label: {}".format(label)) | |
label_i = folder_path+"/"+str(label) | |
#read directory | |
dirs_label_i = os.listdir(label_i) | |
idx = 0 | |
for image in dirs_label_i: | |
#create a absolute image path | |
flower_i = os.path.join(label_i,image) | |
#print('Absolute path for image no. {} and label {}: {}'\ | |
#.format(idx,label,flower_i)) | |
#fill the dataframe with path and label | |
flowers = flowers.append({'image_abs_path':flower_i, | |
'image_labels':flower_names[str(label)]}, | |
ignore_index=True) | |
idx += 1 | |
return flowers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment