Skip to content

Instantly share code, notes, and snippets.

@Akash-Rawat
Last active July 28, 2021 17:42
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 Akash-Rawat/9c40fac265984e7d58f37edd7b9ebe08 to your computer and use it in GitHub Desktop.
Save Akash-Rawat/9c40fac265984e7d58f37edd7b9ebe08 to your computer and use it in GitHub Desktop.
train="SPORT_1/train"
test="SPORT_1/test"
filepaths_train = list(glob.glob(train+'/**/*.jpg'))
filepaths_test = list(glob.glob(test+'/**/*.jpg'))
def proc_img(filepath):
""" Create a DataFrame with the filepath and the labels of the pictures
"""
labels = list(map(lambda x: os.path.split(os.path.split(x)[0])[1], filepath))
filepath = pd.Series(filepath, name='Filepath').astype(str)
labels = pd.Series(labels, name='Label')
# Concatenate filepaths and labels
df = pd.concat([filepath, labels], axis=1)
train_df = proc_img(filepaths_train)
test_df = proc_img(filepaths_test)
print(f'Number of training pictures: {train_df.shape[0]}')
print(f'Number of test pictures: {test_df.shape[0]}')
# Shuffle the DataFrame and reset index
df = df.sample(frac=1).reset_index(drop = True)
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment