how to transform a folder of images into csv file? I have a data set for segmentation project. The dataset have 2 folders containing train folder and annotated_train_data folder, both folders have images. input and label both are images. I want to make a csv file of this dataset to feed into a neural network. what is the easiest and efficient way to make csv file?

./images
./images/train
./images/train/label1.jpg
./images/train/label2.jpg
./images/train/label3.jpg
./images/annotated_train_data
./images/annotated_train_data/label1.jpg
./images/annotated_train_data/label2.jpg
./images/annotated_train_data/label3.jpg
import os
import pandas as pd

BASE_DIR = 'images/'
train_folder = BASE_DIR+'train/'
train_annotation = BASE_DIR+'annotated_train_data/'

files_in_train = sorted(os.listdir(train_folder))
files_in_annotated = sorted(os.listdir(train_annotation))

images=[i for i in files_in_train if i in files_in_annotated]

df = pd.DataFrame()
df['images']=[train_folder+str(x) for x in images]
df['labels']=[train_annotation+str(x) for x in images]

pd.to_csv('files_path.csv', header=None)


Try this.