Skip to content

Instantly share code, notes, and snippets.

@RishiRajak
Created July 12, 2021 15:35
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/880280299f75629bcf0d4920d7e0fe19 to your computer and use it in GitHub Desktop.
Save RishiRajak/880280299f75629bcf0d4920d7e0fe19 to your computer and use it in GitHub Desktop.
#Function that can build a dataframe on passing folderpath.
def getdata(folder_path):
sig = pd.DataFrame(columns=['image_abs_path','image_labels'])
for key,value in labelnames.items():
#print("processing for label: {}".format(label))
label_i = folder_path+"/"+str(key)
#read directory
dirs_label_i = os.listdir(label_i)
idx = 0
for image in dirs_label_i:
#create a absolute image path
sig_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
sig = sig.append({'image_abs_path':sig_i,
'image_labels':key},
ignore_index=True)
idx += 1
return sig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment