Skip to content

Instantly share code, notes, and snippets.

@HSShashank
Created August 25, 2021 05:03
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 HSShashank/a3b2ac7d0570ed1579375bee8473fa42 to your computer and use it in GitHub Desktop.
Save HSShashank/a3b2ac7d0570ed1579375bee8473fa42 to your computer and use it in GitHub Desktop.
labels = []
img_names = []
img_paths = []
gender = []
for file in os.listdir(dir):
if file.endswith('.txt'):
with open(os.path.join(dir, file), 'r') as t:
content = t.readlines()
gender.append(content[0].rsplit(' ')[1][0])
img_name = content[2].rsplit(' ')[1][:-4] + '.png'
img_paths.append(os.path.join(dir,img_name))
img_names.append(img_name)
labels.append((content[1].rsplit(' ')[1][0]))
df = pd.DataFrame()
df['IMAGE PATH'] = img_paths
df['IMAGE NAME'] = img_names
df['LABEL'] = labels
df['GENDER'] = gender
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment