Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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