Last active
August 26, 2021 12:12
-
-
Save KananMahammadli/197d3d5eaceb340bd4819deaed98314f 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
dataset_folder = 'dataset' | |
train_images = [] | |
train_labels = [] | |
test_images = [] | |
test_labels = [] | |
for folder in os.listdir(dataset_folder): | |
folder_path = os.path.join(dataset_folder, folder) | |
if folder == 'train_images': | |
for file in os.listdir(folder_path): | |
if file.endswith('jpg'): | |
img_path = os.path.join(folder_path, file) | |
img = cv2.imread(img_path) | |
train_images.append(img) | |
train_labels.append(df_train.loc[file, 'labels']) | |
elif folder == 'test_images': | |
for file in os.listdir(folder_path): | |
if file.endswith('jpg'): | |
img_path = os.path.join(folder_path, file) | |
img = cv2.imread(img_path) | |
test_images.append(img) | |
test_labels.append(test_df.loc[file, 'labels']) | |
else: | |
pass | |
train_images = np.array(train_images) | |
train_labels = np.array(train_labels) | |
test_images = np.array(test_images) | |
test_labels = np.array(test_labels) | |
print('Shape of stacked train images:', train_images.shape) | |
print('Shape of train labels:', train_labels.shape) | |
print('Shape of stacked test images:', test_images.shape) | |
print('Shape of test labels:', test_labels.shape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment