Last active
July 28, 2021 17:42
-
-
Save Akash-Rawat/9c40fac265984e7d58f37edd7b9ebe08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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