Skip to content

Instantly share code, notes, and snippets.

@RishiRajak
Created June 29, 2021 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RishiRajak/06a1606a6ea1a698eb7d1cc3f930ad68 to your computer and use it in GitHub Desktop.
Save RishiRajak/06a1606a6ea1a698eb7d1cc3f930ad68 to your computer and use it in GitHub Desktop.
dataframe of image paths and labels
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